Linux cmp command - compare two files by bytes

Linux cmp command: compare two files by bytes

Linux cmp command Function Description

Use the cmp command to compare two files by bytes and see if the files differ.

Linux cmp command Syntax

cmp [option] [file1] [file2 [Byte count1 [Byte count2]]]

The meaning of each option in the command is shown in the table:

Option Description
-l Output the number of bytes and values of all different bytes
-n <Byte count> Compare by specified minimum bytes
-b Display different bytes
-i <Byte count> Skip the first few bytes of the loser
-i <Byte Count1>:<Byte Count2> Skip the first few bytes of file 1 and file 2
-s No error message is displayed

Linux cmp command Demo

Compare apidemos.com.sort.txt and apidemos.com.txt files by bytes

cmp apidemos.com.sort.txt apidemos.com.txt

Output:

Linux cmp command

Compare /root/ab and /root/ac files by bytes

[root@rhel ~]# cmp /root/ab /root/ac
/root/ab /root/ac differ: byte 6, line 2

Compare /root/ab and /root/ac files by byte, skipping the first 2 bytes of input

[root@rhel ~]# cmp -i 2 /root/ab /root/ac

Compare /root/ab and /root/ac files by byte, skipping the first 1 byte of file 1 and the first 2 bytes of file 2

[root@rhel ~]# cmp -i 1:2 /root/ab /root/ac

Compare /root/ab and /root/ac files by byte, output byte count and value.

[root@rhel ~]# cmp -l /root/ab /root/ac
6 12144
cmp: EOF on /root/ab
Like(1)

Related

Linux Login Logout Command
Linux login commandLinux logout commandLinux nologin commandLinux exit commandLinux sulogin commandLinux rlogin commandLinux poweroff commandLinux ctrlaltdel CommandLinux shutdown commandLinux halt commandLinux reboot commandLinux init commandLinux runlevel commandLinux telinit command
Linux File Management Command
Linux cat commandLinux tac commandLinux nl commandLinux more commandLinux less commandLinux head commandLinux tail commandLinux rev commandLinux fold commandLinux fmt commandLinux expand commandLinux pr commandLinux sort commandLinux uniq commandLinux cut commandLinux comm commandLinux diff commandLinux join commandLinux diff3 commandLinux cmp commandLinux colrm commandLinux paste commandLinux mkdir commandLinux tr commandLinux split commandLinux csplit commandLinux tee commandLinux unexpand commandLinux patch commandLinux awk commandLinux sed commandLinux od commandLinux pwd commandLinux cd commandLinux ls commandLinux dir commandLinux dirs commandLinux touch commandLinux rmdir commandLinux cp commandLinux mv commandLinux rm commandLinux install commandLinux tmpwatch commandLinux file commandLinux du commandLinux wc commandLinux tree commandLinux cksum commandLinux md5sum commandLinux sum commandLinux dirname commandLinux mkfifo Command
Cron Expressions
Cron Expression to Run Every Day at 12 PMUnderstanding Vue Cron ExpressionsUnderstanding JS Cron ExpressionsA Comprehensive Guide to Cron Expressions for Scheduled TasksUnderstanding Linux Cron ExpressionsUnderstanding Quartz Cron ExpressionsCron ExpressionCron Time ExpressionCron Expression ParsingCron Expression: Executing a Task Every SecondCron Expression for Every Minute ExecutionCron Expression to Execute Every 10 MinutesCron Expression: Executing Every HourCron Expression to Execute Once a YearCron Expression: How to Schedule a Task to Run Daily at Midnight?