Linux共通テキストペアリングコマンド-diff
8986 ワード
一、前言
Windows環境では、ファイルの比較に強力でフレンドリーなBeyond Compareツールを使用することが一般的です.実はLinuxシステムには同じ強力なペアリングコマンドが付属しており、Linuxシステムの下で直接使用することができます.diffコマンドは、2つのファイルの違いに比べて、強力で使いやすいようにします.diffコマンドは行単位で比較され、コマンドがディレクトリの下に使用されている場合は、2つのディレクトリに同じ名前のファイルを比較できます.
二、文法及びパラメータ
三、常用例
1、2つのファイルに対してのみ同じかどうか
2、2つのディレクトリの下のすべてのファイルが同じかどうかを比較する
大きなディレクトリであれば、異なるファイルが非常に多く、表示が不便で記録ファイルが得られる場合は、リダイレクトを使用してログにリダイレクトします.
あとでfilelist.logファイルを見ればいいです
3、二つのファイルを比較して異常位置を表示する
「|」は前後の2つのファイルの内容が異なることを示します「>」は、後のファイルが前のファイルより1行多いことを示します.
Windows環境では、ファイルの比較に強力でフレンドリーなBeyond Compareツールを使用することが一般的です.実はLinuxシステムには同じ強力なペアリングコマンドが付属しており、Linuxシステムの下で直接使用することができます.diffコマンドは、2つのファイルの違いに比べて、強力で使いやすいようにします.diffコマンドは行単位で比較され、コマンドがディレクトリの下に使用されている場合は、2つのディレクトリに同じ名前のファイルを比較できます.
二、文法及びパラメータ
diff (- ) ( 1/ 1) ( 2/ 2)
-< >: 。 -c -u ;
-a ——text:diff ;
-b --ignore-space-change: ;
-B --ignore-blank-lines: ;
-c: , ;
-C< > --context< >: “-c-< >” ;
-d ——minimal: , ;
-D< > ifdef< >: ;
-e ——ed: ed script ;
-f -forward-ed: ed script , ;
-H --speed-large-files: , ;
-l< > --ignore-matching-lines< >: , , ;
-i --ignore-case: ;
-l ——paginate: pr ;
-n ——rcs: RCS ;
-N --new-file: , A , :Only in , A -N , diff A ;
-p: C , ;
-P --unidirectional-new-file: -N , , ;
-q --brief: , ; -r ——recursive: ;
-s --report-identical-files: , ;
-S< > --starting-file< >: , ;
-t --expand-tabs: , tab ;
-T --initial-tab: tab ;
-u,-U< > --unified=< >: ;
-v ——version: ; -w --ignore-all-space: ;
-W< > --width< >: -y , ;
-x< > --exclude< >: ;
-X< > --exclude-from< >; , =< > ;
-y --side-by-side: ;
--help: ;
--left-column: -y , , ;
--suppress-common-lines: -y , 。
三、常用例
1、2つのファイルに対してのみ同じかどうか
[roy@localhost Test]$ diff -q 1.txt 2.txt
Files 1.txt and 2.txt differ
2、2つのディレクトリの下のすべてのファイルが同じかどうかを比較する
[roy@localhost Documents]$ diff -rqN ./Test ./Test1
Files ./Test/1.txt and ./Test1/1.txt differ
Files ./Test/2.txt and ./Test1/2.txt differ
大きなディレクトリであれば、異なるファイルが非常に多く、表示が不便で記録ファイルが得られる場合は、リダイレクトを使用してログにリダイレクトします.
[roy@localhost Documents]$ diff -rqN ./Test ./Test1 > filelist.log
あとでfilelist.logファイルを見ればいいです
3、二つのファイルを比較して異常位置を表示する
[roy@localhost Test]$ diff -y 1.txt 2.txt
a a
b b
c c
d d
e e
f f
g g
h h
j |h
k |h
l |h
m |h
n |h
「|」は前後の2つのファイルの内容が異なることを示します「>」は、後のファイルが前のファイルより1行多いことを示します.