Close Menu
  • Analog Design
    • Latest Analog Layout Interview Questions (2025)
  • Digital Design
    • Digital Electronics Interview Question(2025)
    • Top VLSI Interview Questions
  • Physical Design
    • Physical Design Interview Questions for VLSI Engineers
  • Verilog
    • Verilog Interview Questions(2024)
  • Forum
Facebook Instagram YouTube LinkedIn WhatsApp
SiliconvlsiSiliconvlsi
Forum Questions Register in Forum Login in Forum
Facebook Instagram YouTube LinkedIn WhatsApp
  • Analog Design
    • Latest Analog Layout Interview Questions (2025)
  • Digital Design
    • Digital Electronics Interview Question(2025)
    • Top VLSI Interview Questions
  • Physical Design
    • Physical Design Interview Questions for VLSI Engineers
  • Verilog
    • Verilog Interview Questions(2024)
  • Forum
SiliconvlsiSiliconvlsi
Home»Linux»What is the cmp Command in Linux/UNIX?
Linux

What is the cmp Command in Linux/UNIX?

siliconvlsiBy siliconvlsiJanuary 20, 2024No Comments2 Mins Read
Facebook Pinterest LinkedIn Email WhatsApp
Share
Facebook Twitter LinkedIn Pinterest Email

What is the cmp Command in LinuxUNIX

CMP Command in Linux/UNIX

The cmp command in Linux/UNIX is used to compare two files byte by byte, helping determine whether the two files are identical or not. When used for comparison, cmp reports the location of the first mismatch if differences are found. If the files are identical, cmp display no message and return the prompt.

Syntax:

cmp [OPTION]... FILE1 [FILE2 [SKIP1 [SKIP2]]]
  • OPTION: Optional flags that control the behavior of the command.
  • FILE1 and FILE2: Filenames of the two files to be compared.
  • SKIP1 and SKIP2: Optional number of bytes to skip at the beginning of each file (default is 0).

Example:

$ cmp file1.txt file2.txt
Options for cmp Command:

-b (print-bytes): Displays differing bytes in the output when used with -b option.

$ cmp -b file1.txt file2.txt file1.txt file2.txt differ

-i [bytes-to-be-skipped]: Skips a specified number of initial bytes from both files and then compares them.

$ cmp -i 10 file1.txt file2.txt

-i [bytes-to-be-skipped1:bytes-to-be-skipped2]: Skips several bytes separately from each file.

$ cmp -i 10:12 file1.txt file2.txt

-l (list): Prints byte position and byte value for all differing bytes.

$ cmp -l file1.txt file2.txt

-s (silent): Compares files without writing any messages. Exit values: 0 (identical), 1 (different), 2 (error).

$ cmp -s file1.txt file.txt

-n [number of bytes]: Limits the number of bytes to be compared.

$ cmp -n 50 file1.txt file2.txt

--version: Outputs version information and exits.

$ cmp --version

--help: Displays a help message and exits.

$ cmp --help

These options provide flexibility in how the cmp the command operates, allowing users to tailor the comparison based on their specific needs.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

Related Posts

Delete words after certain word in each line in gvim

January 28, 2024

Linux date Command

January 22, 2024

What is a Linux locate Command?

January 22, 2024
Leave A Reply Cancel Reply

Facebook X (Twitter) Instagram Pinterest Vimeo YouTube
  • About Us
  • Contact Us
  • Privacy Policy
© 2025 Siliconvlsi.

Type above and press Enter to search. Press Esc to cancel.