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.

cmp file1 file2

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.

cmp file1 file2 both files are identical

Comparing two files using cmp command where the contents of two files are identical in first two lines and different from third line.

cmp file1 file2 two lines are indentical

 

cmp -l file1 file2

cmp -l flle1 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

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 file1 file2

cmp -n 30 1.txt 4.txt
// since no message in output, indicating files are identical for first bytes.

cmp -n f1 f2

Skipping a particular number of bytes from both files

cmp -i INT file1 file2

cmp -i INT file1 file2

cmp -i INT1:INT2 file1 file2

cmp -i INT1 INT2 file1 file2

A
adduser | addgroup | alias | anacron | apt | aptitude | arp | at | atq | atrm | awk
B
basename | banner | batch | bc | bg | bzip
C
cat | cal | cd | chgrp | chown | cksum | chmod | clear | cmp | comm | cp
D
date | dd | df | diff | dir | dmidecode | du
E
echo | eject | env | exit | expr
F
factor | find | free
G
grep | groups | gunzip | gzip
H
head | history | hostname | hostnamectl | htop | hwclock | hwinfo
I
id | ifconfig | ionice | iostat | ip | iptables | iw | iwlist
J
K
kill | kmod
L
last | less | ln | locate | login | lp | ls | lshw | lscpu | lsof | lsusb
M
man | mdsum | mkdir | more| mv
N
nano | nc | neofetch | netcat | netstat | nice | nmap | nproc
O
openssl
P
passwd | pidof | ping | pr | ps | pwd | pstree
Q
R
rdiff-backup | reboot | rename | rm | rmdir | rnmod
S
scp | shred | shutdown | sleep | sort | split | ssh | stat | su | sudo | sum
T
tac | tail | talk | tar | tee | time | tree | top | touch | tr
U
unalias | uname | uniq | unzip | uptime | users
V
vim | vi
W
w | wall | watch | wc | wget | whatis | whereis | which | who | whoami
X
xargs
Y
yes | youtube-dl
Z
zcmp | zdiff | zip | zz

Sharing is Caring
Scroll to Top