cmp
Command Cheatsheet
The cmp
command in Unix-like systems is used to compare two files byte by byte. It is useful for finding the first difference between two files. Here’s a quick reference guide:
Basic Syntax
cmp [OPTION]... FILE1 FILE2
Common Options
-b
,--print-bytes
: Output differing bytes in decimal format.cmp -b file1.txt file2.txt
-i POS
,--ignore-initial=POS
: Ignore the first POS bytes of each file.cmp -i 10 file1.txt file2.txt
-l
,--line-by-line
: Output the byte number and the differing bytes.cmp -l file1.txt file2.txt
-s
,--silent
,--quiet
: Suppress all output, only return exit status.cmp -s file1.txt file2.txt
-v
,--verbose
: Output a message when files differ.cmp -v file1.txt file2.txt
Examples
Compare two files and print the first difference:
cmp file1.txt file2.txt
Compare files byte by byte and print differing bytes in decimal format:
cmp -b file1.txt file2.txt
Ignore the first 10 bytes and compare the rest of the files:
cmp -i 10 file1.txt file2.txt
Output the byte number and differing bytes:
cmp -l file1.txt file2.txt
Silent comparison, only return exit status:
cmp -s file1.txt file2.txt
Verbose output when files differ:
cmp -v file1.txt file2.txt
Additional Information
Help option:
cmp --help
View
cmp
manual page:man cmp
This cheatsheet covers the essential options and usage scenarios for the cmp
command. For more detailed information, refer to the man
page or use cmp --help
.