Forrest logo
tool overview
On this page you find all important commands for the CLI tool cmp. If the command you are looking for is missing please ask our AI.

cmp

The cmp command line tool is used to compare two files byte by byte and to output the first byte position where they differ. It is available on Unix-like operating systems, including Linux and macOS.

Here are a few key features and usage options of cmp:

  • By default, cmp compares two files and displays no output if they are identical. If any differences are found, it reports the byte offset where the first difference occurs.
  • The -l option displays byte differences in a more detailed format, showing the differing byte values and their offsets.
  • The -b option is used to compare two files in binary mode, treating all bytes as data without any special interpretation.
  • To compare specific byte ranges within files, you can use the -n option followed by the number of bytes to compare.
  • The -i option allows you to skip a specified number of bytes at the beginning of each file before comparison.
  • When cmp encounters read errors while comparing files, it reports them along with the corresponding error code.
  • The exit status of the cmp command reflects the result of the comparison. If the files differ, the exit status is non-zero (1), and if they are identical, the exit status is 0.

Overall, cmp is a handy tool for comparing files at the binary level in the command line environment.

List of commands for cmp:

  • cmp:tldr:45e91 cmp: Output char and line number of the first difference between two files.
    $ cmp ${filename1} ${filename2}
    try on your machine
    explain this command
  • cmp:tldr:9792d cmp: Compare files but output nothing, yield only the exit status.
    $ cmp --quiet ${filename1} ${filename2}
    try on your machine
    explain this command
  • cmp:tldr:ecc89 cmp: Output the byte numbers and values of every difference.
    $ cmp --verbose ${filename1} ${filename2}
    try on your machine
    explain this command
tool overview