diffコマンド
スポンサードリンク
【説明】
2 つのファイルを比較し、それらの違いを記述して出力する際に使用します。
ファイルのうちのどちらかは ‘-’ と指定しても良い。この時はそのファイルは標準入力 から読み込まれます。両方がディレクトリのときは、 diff
は双方のディレクトリにある、対応するファイルをアルファベット順にそれぞれ比較します。比較は再帰的には行われないが、 -r ま た は--recursive
オプションを指定すれば再帰的になります。
【構文】
diff [オプション] [ファイル1] [ファイル2]
例 test1ファイルとtest2ファイルを比較する。
[root@localhost test]# cat test1
aaa
bbb
[root@localhost test]# cat test2
aaa
ccc
[root@localhost test]# diff test1 test2
2c2
< bbb
---
> ccc |
例 test1とtest2をunified形式で比較する。
[root@localhost test]# cat test1
aaa
bbb
[root@localhost test]# cat test2
aaa
ccc
[root@localhost test]# diff -u test1 test2
--- test1 2008-06-18 08:05:31.000000000 +0900
+++ test2 2008-06-18 08:05:37.000000000 +0900
@@ -1,2 +1,2 @@
aaa
-bbb
+ccc |
例 見やすいようにside-by-side 出力形式でtest1とtest2を比較する。
[root@localhost test]# diff -y test1 test2
aaa aaa
bbb | ccc |
|
|