Unix-commands-cmp

提供:Dev Guides
移動先:案内検索

cmp-Unix、Linuxコマンド

NAME

*cmp* -2つのファイルを比較し、それらが異なる場合、最初のバイトと行番号にそれらの違いを伝えます。

概要

cmp options... FromFile [ToFile]

説明

'cmp’は、2つのファイルの違いを1行ずつではなく1文字ずつ報告します。 その結果、バイナリファイルの比較には「diff」よりも便利です。 テキストファイルの場合、「cmp」は主に、2つのファイルが同一かどうかだけを知りたいときに役立ちます。 同一のファイルの場合、「cmp」は出力を生成しません。 ファイルが異なる場合、デフォルトでは、「cmp」は最初の違いが発生するバイトオフセットと行番号を出力します。 「-s」オプションを使用してその情報を抑制することができるため、「cmp」は出力を生成せず、終了ステータスのみを使用してファイルが異なるかどうかをレポートします。 「diff」とは異なり、「cmp」はディレクトリを比較できません。 2つのファイルのみを比較できます。

オプション

-c Print the differing characters. Display control characters as a '^' followed by a letter of the alphabet and precede characters that have the high bit set with 'M-' (which stands for "meta").
--ignore-initial=BYTES Ignore any differences in the the first BYTES bytes of the input files. Treat files with fewer than BYTES bytes as if they are empty.
-l Print the (decimal) offsets and (octal) values of all differing bytes.
--print-chars Print the differing characters. Display control characters as a '^' followed by a letter of the alphabet and precede characters that have the high bit set with 'M-' (which stands for "meta").
--quiet-s—​silent Do not print anything; only return an exit status indicating whether the files differ.
--verbose Print the (decimal) offsets and (octal) values of all differing bytes.
-v—​version Output the version number of 'cmp'. The file name '-' is always the standard input. 'cmp' also uses the standard input if one file name is omitted. An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble.

2つのファイルを比較する

$ cat sample.txt
This is a sample text file
$ cat sample1.txt
This is another sample file
$ cmp sample.txt sample1.txt
sample.txt sample1.txt differ: byte 10, line 1

link:/cgi-bin/printpage.cgi [__印刷]