cmp command in Linux is used to compare the content of two files byte by byte and reports the first byte and line number where they differ.
Syntax of cmp command
cmp [options] file1 file2
Here is a list and contents of text files, used for cmp command in this tutorial.
Compare two files
cmp command is used to compare the contents of two files byte by byte. To compare the contents of two files byte by byte use the following command.
cmp file1 file2
Comparing two files using cmp command where the contents of two files are different from the first line.
Comparing two files using cmp command where the contents of two files are identical (no difference). If no difference is found, cmp command displays nothing and simply returns the prompt.
Comparing two files using cmp command where the contents of two files are identical in first two lines and different from third line.
cmp -l file1 file2
Display differing bytes
Use -b option along with cmp command to display the differing bytes in the output, when two files are compared.
cmp -b file1 file2
Limit the number of bytes to compare
Use -n option along with cmp command if you do not wants to compare the entire contents of two files and only want to compare first few bytes of two files.
cmp -n INT file1 file2
cmp -n 30 1.txt 4.txt // since no message in output, indicating files are identical for first bytes.
Skipping a particular number of bytes from both files
cmp -i INT file1 file2
cmp -i INT1:INT2 file1 file2
Linux command with examples
date | dd | df | diff | dir | dmidecode | du
echo | eject | env | exit | expr
grep | groups | gunzip | gzip
kill | kmod
man | mdsum | mkdir | more| mv
passwd | pidof | ping | pr | ps | pwd | pstree
rdiff-backup | reboot | rename | rm | rmdir
tac | tail | talk | tar | tee | time | tree | top | touch | tr
unalias | uname | uniq | unzip | uptime | users
vim | vi
yes | youtube-dl
zcmp | zdiff | zip | zz