[Previous] [Contents] [Next]

cmp

Compare two files (POSIX)

Syntax:

cmp [-l|-s] file1 file2

Options:

-l
("el") Print the byte position (in decimal) and the differing bytes (octal) for all differences (not just the first one) between the two files.
-s
Be silent. Return exit status only.
file1
The pathname of the first file to be compared. If file1 is the dash character (-), the standard input is used.
file2
The pathname of the second file to be compared.

Description:

The cmp utility compares two files. If you don't specify any options, cmp behaves as follows:

If you specify both the -s and -l options, nothing is printed (no long output).

Examples:

Compare the files test.dat and save.dat:

cmp test.dat save.dat

Files:

The standard input will be used only if one of the command-line file parameters is -.

The results of the file comparison are written to the standard output.

If errors occur, diagnostic messages will be written to the standard error.

Exit status:

0
The files are identical.
1
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).
>1
An error occurred.

See also:

cksum, diff, wc


[Previous] [Contents] [Next]