cmp - Unix, Linux Command


Advertisements


NAME

cmp - Compare two files, and if they differ, tells the first byte and line number where they differ.

SYNOPSIS

cmp options... FromFile [ToFile]

DESCRIPTION

'cmp' reports the differences between two files character by character, instead of line by line. As a result, it is more useful than 'diff' for comparing binary files. For text files, 'cmp' is useful mainly when you want to know only whether two files are identical. For files that are identical, 'cmp' produces no output. When the files differ, by default, 'cmp' outputs the byte offset and line number where the first difference occurs. You can use the '-s' option to suppress that information, so that 'cmp' produces no output and reports whether the files differ using only its exit status. Unlike 'diff', 'cmp' cannot compare directories; it can only compare two files.

OPTIONS

-cPrint the differing characters. Display control characters as a '^' followed by a letter of the alphabet and precede characters that have the high bit set with 'M-' (which stands for "meta").
--ignore-initial=BYTESIgnore any differences in the the first BYTES bytes of the input files. Treat files with fewer than BYTES bytes as if they are empty.
-lPrint the (decimal) offsets and (octal) values of all differing bytes.
--print-charsPrint the differing characters. Display control characters as a '^' followed by a letter of the alphabet and precede characters that have the high bit set with 'M-' (which stands for "meta").
--quiet
-s
--silent
Do not print anything; only return an exit status indicating whether the files differ.
--verbosePrint the (decimal) offsets and (octal) values of all differing bytes.
-v
--version
Output the version number of 'cmp'. The file name '-' is always the standard input. 'cmp' also uses the standard input if one file name is omitted. An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble.

EXAMPLES

Compare two files

$ cat sample.txt
This is a sample text file
$ cat sample1.txt
This is another sample file
$ cmp sample.txt sample1.txt
sample.txt sample1.txt differ: byte 10, line 1


Advertisements