Name
cmp
Synopsis
cmp [options
]file file2
[skip1
[skip2
]]
Compares file1
with file2
. Use standard input if file1
or file2
is -. To begin the comparison from byte offsets other than at the beginning of the files, use the optional arguments skip1
and skip2
, which specify the byte offsets from the beginning of each file. By default, the value is decimal. To use hexadecimal or octal values, precede them with a leading 0x or 0, respectively. See also
comm
and
diff
. The exit codes are as follows:
- 0
Files are identical.
- 1
Files are different.
- 2
Files are inaccessible.
Options
- -c, --print-chars
Print differing bytes as characters.
-
-i
N
, --ignore-initial=N
Ignore differences in the first
N
bytes of input.-
-n
limit,
--bytes=limit
Compare at most
limit
bytes of input.- -l
For each difference, print the byte number in decimal and the differing bytes in octal.
- -s
Work silently; print nothing, but return exit codes.
- -v, --version
Output version info.
Example
Print a message if two files are the same (exit code is 0):
$ cmp -s old new && echo 'no changes'
Get Mac OS X Tiger in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.