cmp |
[-bcdilns ] file1 file2
[skip1 [skip2]] |
The cmp
utility compares two files.
cmp
writes no output if the files are the same. Under
default options, if they differ, it writes to standard output the byte and
line numbers at which the first difference occurred. Bytes and lines are
numbered beginning with 1. skip1 and
skip2 are initial byte offsets into
file1 and file2 respectively, and
are specified in bytes or can be given with a suffix of
k
for kilobytes or m
for
megabytes.
If either file1 or
file2 is a dash (−),
cmp
uses standard input starting at the current
location.
The following options are supported:
-b
,
--print-bytes
- Print differing bytes as 3-digit octal values.
-c
,
--print-chars
- Print differing bytes as follows:
- non-space printable characters as themselves;
- space and control characters as ^ followed by a
letter of the alphabet;
- characters with the high bit set as the lower 7-bit character prefixed
by M^ for 7-bit space and non-printable characters,
and M- for all other characters. If the 7-bit
character encoding is not ASCII then the characters are converted to
ASCII to determine whether the high bit is set and, if set, it is
cleared and converted back to the native encoding. Multibyte
characters in the current locale are treated as printable
characters.
-d
differences,
--differences
=differences
- Print at most differences differences using
-l
(--verbose
) output
format. If differences is 0
then this is equivalent to passing the -s
or
--silent
option.
-i
skip1[:skip2,
--skip
=skip1[:skip2,
--ignore-initial
=skip1[:skip2]]]
- Skip the first skip1 bytes in
file1 and the first skip2
bytes in file2. If skip2 is
omitted then skip1 is used for that value. The
default value is 0:0.
-l
,
--verbose
- Write the byte number (decimal) and the differing bytes (octal) for each
difference.
-n
count,
--count
=count,
--bytes
=count
- Compare at most count bytes.
-s
,
--silent
-,
--quiet
- Write nothing for differing files. Return exit status only.
The following operands are supported:
- file1
- A path name of the first file to be compared. If
file1 is −, the
standard input is used.
- file2
- A path name of the second file to be compared. If
file2 is −, the
standard input is used.
- skip1
- The number of initial bytes from file1 to skip
before beginning the comparison.
- skip2
- The number of initial bytes from file2 to skip
before beginning the comparison. If skip1 is
specified but skip2 is not, then the value of
skip1 is also implicitly used for
skip2.
If both file1 and
file2 refer to standard input or refer to the same
FIFO, block or character special file, an error results.
skip values are specified in bytes, or can
be suffixed with k
(for kilobytes) or
m
(for megabytes.)
The following exit values are returned:
- 0
- The files or portions compared are identical.
- 1
- The files or portions compared are different.
- >1
- An error ocurred.
- Example 1 Comparing Files Byte for
Byte
- The following example does a byte for byte comparison of
file1 and file2, skipping the
first 1024 bytes in file2 before starting the
comparison.
See environ(5) for descriptions of the following environment
variables that affect the execution of cmp
:
LANG
, LC_ALL
,
LC_TYPE
, LC_MESSAGES
,
LC_NUMERIC
, and NLSPATH
.
The command line interface of cmp
is
Committed. The output of cmp
is
Standard.