CMP(1) General Commands Manual CMP(1)

cmpcompare two files

cmp [-ls] [-n max_bytes] file1 file2

The cmp utility checks files file1 and file2 for a different byte and prints it out.

The following options are supported:

Write the byte number and if found, the two bytes found different.
max_bytes
Only compare the first max_bytes.
Write nothing when files differ, errors are still printed out to stderr.

When a difference is found, the default message format is:

“%s %s differ: char %d, line %d\n”, file1, file2, ⟨byte position within line⟩ ⟨line position

When -l is passed, the format is:

“%d %o %o\n”, ⟨byte position⟩, ⟨file1 byte⟩, ⟨file2 byte

When -s is passed, nothing should be printed to standard output.

If -s is not passed, and a file is shorter than the other, an error with the following format is printed:

“cmp: EOF on %s line %ld\n”, ⟨name of shorter file⟩, ⟨line number

Note that unlike the other formats, only the following format is standard:

“cmp: EOF on %s%s\n”, ⟨name of shorter file⟩, ⟨additional info
Where ⟨additional info⟩ can be empty or have any single-line information starting with a space.

0
The files are identical.
1
The files are different.
>1
An error occurred.

cmp should be compliant with the IEEE Std 1003.1-2024 (“POSIX.1”) specification. The -n max_bytes option is an extension.

Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>

2024-05-02 Linux 6.6.67-gentoo-x86_64