Name

cmp

Synopsis

    cmp [options] file1 file2 [skip1 [skip2]]

Compare file1 with file2. Use standard input if file1 or file2 is -. (See also comm and diff.) skip1 and skip2 are optional offsets in the files at which the comparison is to start. The exit codes are as follows:

0

Files are identical.

1

Files are different.

2

Files are inaccessible.

Common Options

-l, --verbose

Print offsets and codes of all differing bytes.

-s, --quiet, --silent

Work silently; print nothing, but return exit codes.

GNU/Linux and Mac OS X Options

-b, --print-bytes

Print differing bytes.

-inum1[:num2], --ignore-initial=num1[:num2]

Ignore the first num1 bytes of input. With num2, skip num1 bytes from the first file and num2 bytes from the second file.

-nmax, --bytes=max

Read and compare no more than max bytes.

Example

Print a message if two files are the same (exit code is 0):

    cmp -s old new && echo 'no changes'

Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.