首页
首页 » 文件管理 » cmp(compare)

cmp(compare)

cmp(compare)
功能说明:比较两个文件是否有差异。
语  法:cmp [-clsv][-i <字符数目>][--help][第一个文件][第二个文件]
补充说明:当相互比较的两个文件完全一样时,则该指令不会显示任何信息。若发现有所差异,预设会标示出第一个不同之处的字符和列数编号。若不指定任何文件名称或是所给予的文件名为"-",则cmp指令会从标准输入设备读取数据。
参  数:
 -c或--print-chars  除了标明差异处的十进制字码之外,一并显示该字符所对应字符。 
 -i<字符数目>或--ignore-initial=<字符数目>  指定一个数目。 
 -l或--verbose  标示出所有不一样的地方。 
 -s或--quiet或--silent  不显示错误信息。 
 -v或--version  显示版本信息。 
 --help  在线帮助。

cmp

cmp [options] file1 file2 [skip1 [skip2] ]

Compare file1 with file2. Use standard input if file1 is - or missing. This command is normally used for comparing binary files, although files can be of any type. (See also diff.) skip1 and skip2 are optional offsets in the files at which the comparison is to start.

Options

-c, --print-chars

Print differing bytes as characters.

-i num, --ignore-initial=num

Ignore the first num bytes of input.

-l, --verbose

Print offsets and codes of all differing bytes.

-s, --quiet, --silent

Work silently; print nothing, but return exit codes:

0

Files are identical.

1

Files are different.

2

Files are inaccessible.

Example

Print a message if two files are the same (exit code is 0):

cmp -s old new && echo 'no changes'