cmp

Compare two files for any differences

Supplementary instructions

cmp command is used to compare two files for differences. When two files compared to each other are identical, this command displays no information. If a discrepancy is found, the default character and column number of the first discrepancy will be marked. If no file name is specified or the file name is given as "-", the cmp command will read data from the standard input device.

grammar

cmp(option)(parameter)

Options

-c or --print-chars: In addition to the decimal character code indicating the difference, the characters corresponding to the character are also displayed;
-i<number of characters> or --ignore-initial=<number of characters>: Specify a number;
-l or --verbose: Mark all differences;
-s or --quiet or --silent: Do not display error messages;
-v or --version: display version information;
--help: online help.

Parameters

Directory: Compare the differences between two files.

Example

To use the cmp command to compare the file "testfile" and the file "testfile1", enter the following command:

cmp testfile testfile1 #Compare two specified files

Before the above instructions are executed, use the cat command to view the contents of the two specified files, as shown below:

cat testfile #View file content
Absncn 50 #Display file "testfile"
Asldssja 60
Jslkadjls 85

cat testfile1 #View file content
Absncn 50 #Display file "testfile1"
AsldssjE 62
Jslkadjls 85

Then, execute the cmp command and return the comparison results, as shown below:

cmp testfile testfile1 #Compare two files
testfile testfile1 #There is a difference: byte 8, line 2

Note: In the comparison results, only the first comparison result can be displayed.