cmp (compare files)

Compares two files to see whether they are the same. This command is used to compare binary files. To compare text files, use the diff command.

Format:    cmp file1 file2
Examples:  cmp prog1 prog2

The output depends on the options used.

OptWhat It DoesExample
-cDisplay differing bytes as characterscmp -c file1 file2
-lDisplay location of differing bytescmp -l file1 file3
-sDisplay nothing; return exit codes: 0=identical; 1=different; 2=inaccessiblecmp -s file77 prog3

Get Spring Into Linux® 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.