Compare two files (GNU)


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

Runs on:

QNX Neutrino


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”).
Output a summary of usage and then exit.
-i 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.
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
Compare at most count input bytes.
Don't print anything; only return an exit status indicating whether the files differ.
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.


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


Compare the files myfile.dat and save.dat:

cmp myfile.dat save.dat

Exit status:

The files are identical.
The files differ.
An error occurred.

Contributing author: