cmp

Updated: October 26, 2022

Compare two files (GNU)

Syntax:

cmp optionsfrom-file [to-file [from-skip [to-skip]]]

Runs on:

QNX Neutrino

Options:

-b
--print-bytes
Print the differing bytes. Display control bytes as a caret (^) followed by a letter of the alphabet, and precede bytes that have the high bit set with M- (which stands for “meta”).
--help
Output a summary of usage and then exit.
-i skip
--ignore-initial=skip
Ignore any differences in the first skip bytes of the input files. Treat files with fewer than skip bytes as if they were empty. If skip is of the form from-skip:to-skip, skip the first from-skip bytes of the first input file and the first to-skip bytes of the second.
-l
--verbose
Output the (decimal) byte numbers and (octal) values of all differing bytes, instead of the default standard output. Each output line contains a differing byte’s number relative to the start of the input, followed by the differing byte values. Byte numbers start at 1. Also, output the EOF message if one file is shorter than the other.
-n count
--bytes=count
Compare at most count input bytes.
-s
--quiet
--silent
Don't print anything; only return an exit status indicating whether the files differ.
-v
--version
Output version information and then exit.
from-file, to-file
The files to compare. If you omit to-file or specify a dash (-) for either file, cmp reads from standard input.
from-skip, to-skip
The number of bytes to skip in each file. These values may be followed by a multiplicative suffix: kB for 1000, K for 1024, MB for 1,000,000, M for 1,048,576, GB for 1,000,000,000, G for 1,073,741,824, and so on for T, P, E, Z, and Y.

Description:

The cmp utility compares two files.

Note: This utility is intended for comparing binary files, if you want to compare text files, use diff.

For detailed documentation about cmp, see the GNU website at http://www.gnu.org/.

Examples:

Compare the files myfile.dat and save.dat:

cmp myfile.dat save.dat

Exit status:

0
The files are identical.
1
The files differ.
2
An error occurred.

Contributing author:

GNU