cmp
byte-by-byte file comparison
TLDR
Compare two files
SYNOPSIS
cmp [option]... file1 [file2 [skip1 [skip2]]]
DESCRIPTION
cmp compares two files byte by byte and reports the location of the first difference. By default, it prints the byte number and line number where the files diverge, or produces no output if they are identical.
Unlike diff, which operates on text lines, cmp works at the byte level, making it more efficient and appropriate for binary files. The -s (silent) mode is commonly used in scripts where only the exit status matters: 0 for identical files, 1 for differences, and 2 for errors.
The -l option lists all byte positions where the files differ, along with the differing byte values in octal. The tool can also skip initial bytes in one or both files and limit the comparison to a specified number of bytes.
PARAMETERS
-b, --print-bytes
Print differing bytes-i skip, --ignore-initial skip
Skip first bytes of both files-i skip1:skip2
Skip different amounts per file-l, --verbose
Output all byte differences-n limit, --bytes limit
Compare at most limit bytes-s, --quiet, --silent
Suppress output, exit code only--help
Display help-v, --version
Show version
EXIT STATUS
0: Files are identical
1: Files differ
2: Error occurred
SKIP SUFFIXES
K (1024), M (1048576), G (1073741824)
kB (1000), MB (1000000), GB (1000000000)
CAVEATS
Cannot compare directories, only files. For text file differences, use diff instead. Reading from stdin use - as filename.
