|This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.|
Compare two files (POSIX)
cmp [-l|-s] file1 file2
- (“el”) Print the byte position (in decimal) and the differing bytes (octal) for all differences (not just the first one) between the two files.
- Be silent. Return the exit status only.
- The pathname of the first file to be compared. If file1 is the dash (-) character, standard input is used.
- The pathname of the second file to be compared.
The cmp utility compares two files.
|This utility is intended for comparing binary files, if you want to compare text files, use diff.|
If you don't specify any options, cmp behaves as follows:
- If the two files are the same, cmp writes no output.
- If the files differ, cmp writes to standard output the byte and line number at which the first difference occurred. Bytes and lines are numbered beginning at 1.
If you specify both the -s and -l options, nothing is printed (no long output).
Compare the files myfile.dat and save.dat:
cmp myfile.dat save.dat
- The files are identical.
- The files differ. This includes cases where one file is identical to the first part of the other. In such cases, if you haven't specified the -s option, cmp writes to standard error a message that EOF was reached in the shorter file (before any differences were found).
- An error occurred.