Name
cmp — stdin stdout - file -- opt --help --version
Synopsis
cmp [options]file1 file2[offset1[offset2]]
The cmp command compares
two files. If their contents are the same, cmp reports nothing; otherwise, it lists
the location of the first difference:
$ cmp myfile yourfile myfile yourfile differ: char 494, line 17
By default, cmp does not
tell you what the difference is, only where it is. It also is
perfectly suitable for comparing binary files, as opposed to
diff, which operates best on text
files.
Normally, cmp starts its
comparison at the beginning of each file, but it will start
elsewhere if you provide offsets:
$ cmp myfile yourfile 10 20
This begins the comparison at the tenth character of myfile and the twentieth of yourfile.
Useful options
|
| Long output: print all differences, byte by byte: $ cmp -l myfile yourfile 494 164 172 This means at offset 494 (in decimal), myfile has “t” (octal 164) but yourfile has “z” (octal 172). |
|
|
Silent output: don’t print anything, just exit with an appropriate return code; 0 if the files match, 1 if they don’t. (Or other codes if the comparison fails for some reason.) |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access