Linux cmp Command

Linux 命令大全Linux Command Encyclopedia

The Linux cmp command is used to compare whether two files have differences.

When the two files being compared are exactly the same, this command will not display any information. If differences are found, it will by default indicate the character and column number of the first difference. If no file name is specified or the given file name is "-", the cmp command will read data from the standard input device.

Syntax

cmp [-clsv][-i <字符数目>][--help][第一个文件][第二个文件]

Parameters:

  • -c or --print-chars: In addition to indicating the decimal code of the difference, also display the character corresponding to that code.
  • -i<number of characters> or --ignore-initial=<number of characters>: Specify a number.
  • -l or --verbose: Indicate all the places that differ.
  • -s or --quiet or --silent: Do not display error messages.
  • -v or --version: Display version information.
  • --help: Online help.

Examples

To determine whether two files are identical, enter:

cmp prog.o.bak prog.o 

This compares prog.o.bak and prog.o. If the files are the same, no message is displayed. If the files differ, the first position of difference is shown; for example:

prog.o.bak prog.o differ: char 4, line 1 

If the message cmp: EOF on prog.o.bak is displayed, then the first part of prog.o is the same as prog.o.bak, but there is additional data in prog.o.

Linux 命令大全Linux Command Encyclopedia

Other Extensions