O'Reilly logo

Mac OS X Tiger in a Nutshell by Jason McIntosh, Chuck Toporek, Chris Stone, Andy Lester

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

cmp

Synopsis

cmp [options] file file2 [skip1 [skip2]]

Compares file1 with file2. Use standard input if file1 or file2 is -. To begin the comparison from byte offsets other than at the beginning of the files, use the optional arguments skip1 and skip2, which specify the byte offsets from the beginning of each file. By default, the value is decimal. To use hexadecimal or octal values, precede them with a leading 0x or 0, respectively. See also comm and diff . The exit codes are as follows:

0

Files are identical.

1

Files are different.

2

Files are inaccessible.

Options

-c, --print-chars

Print differing bytes as characters.

-i N, --ignore-initial= N

Ignore differences in the first N bytes of input.

-n limit, --bytes= limit

Compare at most limit bytes of input.

-l

For each difference, print the byte number in decimal and the differing bytes in octal.

-s

Work silently; print nothing, but return exit codes.

-v, --version

Output version info.

Example

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

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required