0% found this document useful (0 votes)
82 views2 pages

CMP Command

The cmp command compares two files byte by byte and reports the first difference found, including the byte number and line number. It exits with a status code of 0 if the files are the same, 1 if different, or 2 if an error occurs. The cmp syntax specifies the files to compare and allows options like skipping bytes, printing differing bytes, or limiting the byte count.

Uploaded by

Darko
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views2 pages

CMP Command

The cmp command compares two files byte by byte and reports the first difference found, including the byte number and line number. It exits with a status code of 0 if the files are the same, 1 if different, or 2 if an error occurs. The cmp syntax specifies the files to compare and allows options like skipping bytes, printing differing bytes, or limiting the byte count.

Uploaded by

Darko
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Linux cmp command

Updated: 04/26/2017 by Computer Hope

• About cmp
• cmp syntax
• cmp examples
• Related commands
• Linux and Unix commands help

About cmp
cmp is used to compare two files byte by byte. If a difference is found, it reports the byte and line
number where the first difference is found. If no differences are found, by default, cmp returns no
output.

cmp syntax
cmp [OPTION]... FILE1 [FILE2 [SKIP1 [SKIP2]]]

Options
The optional SKIP1 and SKIP2 specify the number of bytes to skip at the beginning of each file (zero
by default).
SKIP values may be followed by the following multiplicative suffixes:

kB kilobytes 1000
K kibibytes 1024

MB megabytes 1,000,000

M mebibytes 1,048,576

GB gigabytes 1,000,000,000

G gibibytes 1,073,741,824

...and so on for T, P, E, Z, Y.
If a FILE is specified as '-' or not specified, data is read from standard input. cmp's exit status is 0 if
inputs are the same, 1 if different, or 2 if the program encounters a problem.
Additional options:

-b, --print-bytes Print differing bytes.

-i, --ignore-initial=SKIP Skip first SKIP bytes of both files.

-i, --ignore-initial=SKIP1:SKIP2 Skip first SKIP1 bytes of FILE1 and first SKIP2 bytes of FILE2.

-l, --verbose Output byte numbers and differing byte values.

-n, --bytes=LIMIT Compare at most LIMIT bytes.

-s, --quiet, --silent Suppress all normal output.

--help Display a help message and exit.

-v, --version Output version information and exit.

cmp examples
cmp file1.txt file2.txt

Compares file1 to file2, reading each file byte-by-byte and comparing them until one of the byte pairs
is not equal. When a difference is found, it will output the location in the file where the difference was
found, and exit. Example output:
file.txt file2.txt differ: char 1011, line 112

You might also like