cmp is a shellcommand that compares two files of any type and reports differences. By default, it outputs nothing if the files match. If they differ, it reports the byte and line number of the first difference. The exit code can be used programmatically since it is 0 if the files match, 1 if the files differ or 2 if comparison fails (i.e. inaccessible or missing argument).
Print the differing bytes; display control bytes as a '^' followed by a letter of the alphabet and precede bytes that have the high bit set with 'M-' (which stands for "meta")
No
No
No
No
Yes
No
-h
Do not follow symbolic links
No
No
No
Yes
No
No
-i SKIP, --ignore-initial=SKIP
Skip the first SKIP bytes of input
No
No
No
No
Yes
No
-i SKIP1:SKIP2, --ignore- initial= SKIP1:SKIP2
Skip the first SKIP1 bytes of FILE1 and the first SKIP2 bytes of FILE2
No
No
No
No
Yes
No
-l, --verbose
Print the (decimal) byte numbers and (octal) values of all differing bytes, instead of the default info; also, print the EOF message if one file is shorter than the other
Yes
Yes
Yes
Yes
Yes
Yes
-L
Print the line number of the first differing byte
Yes
Yes
Yes
No
No
No
-n LIMIT, --bytes=LIMIT
Compare at most LIMIT bytes
No
No
No
No
Yes
No
-s, --quiet, --silent
Print nothing; yield exit status only
Yes
Yes
Yes
Yes
Yes
Yes
-t
Text mode where the files are opened in text mode and translated to the CCSID of the job before comparing byte for byte
No
No
No
No
No
Yes
-v, --version
Print version info
No
No
No
No
Yes
No
-x
Like -l but prints in hexadecimal and using zero as index for the first byte in the files
No
No
No
Yes
No
No
-z
For regular files, compare file sizes first, and fail if they are not equal
No
No
No
Yes
No
No
--help
Print command-line help info
No
No
No
No
Yes
No
Operands that are byte counts are decimal by default, but may be preceded by '0' for octal and '0x' for hexadecimal.
A byte count can be followed by a suffix to specify a multiple of that count; in this case an omitted integer is understood to be 1. A bare size letter, or one followed by 'iB', specifies a multiple using powers of 1024. A size letter followed by 'B' specifies powers of 1000 instead. For example, '-n 4M' and '-n 4MiB' are equivalent to '-n 4194304', whereas '-n 4MB' is equivalent to '-n 4000000'. This notation is upward compatible with the SI prefixes[7] for decimal multiples and with the IEC 60027-2 prefixes for binary multiples.[8]
Example
Example use to report different bytes between text files