linux diff命令_Linux diff命令示例
linux diff命令
The Linux diff command analyses a file line by line and gives an output of a list of changes made between two files.
Linux diff命令逐行分析文件,并輸出兩個文件之間所做更改的列表。
The command diff is short for difference, which in essence?gives the differences between two files.
diff是差異的縮寫,本質上是兩個文件之間的差異?。
Unlike the?cmp?(compare) and?comm?commands, diff highlights the specific line that needs to be changed to match the other files.
與cmp?(比較)和comm命令不同,diff突出顯示需要更改以匹配其他文件的特定行。
One thing Linux administrators cannot forget is that diff uses symbols and instructions to make it more effective.
Linux管理員不能忘記的一件事是,diff使用符號和說明來使其更加有效。
The specific symbols instruct the command to change the file in a particular way to match the second.
特定符號指示命令以特定方式更改文件以匹配第二種。
Special Symbols in the diff command output:
diff命令輸出中的特殊符號:
- a: add 答:添加
- c: change c:變更
- d: delete d:刪除
Linux diff命令語法?(Linux diff Command Syntax)
diff [options] File1 File2Let’s have a look at diff command example usages.
讓我們看一下diff命令示例用法。
情況1:變更?(Case 1: Change)
Assume we have two files:?x.txt?and?y.txt
假設我們有兩個文件:?x.txt和y.txt
x.txt?contains the following content.
x.txt包含以下內容。
California
Miami
Ohio
Kansas
Texas
y.txt?contains the following content.
y.txt包含以下內容。
California
Nevada
Georgia
Kansas
Texas
Now, use the diff command to make the comparison between the two files as shown.
現在,使用diff命令在兩個文件之間進行比較,如圖所示。
$ diff x.txt y.txtSample output
樣品輸出
Let’s examine the output in more detail.
讓我們更詳細地檢查輸出。
The?2,3c2,3?line implies that lines 2 and 3 from the first file need to be changed in order to match lines 2 and 3 from the second text file.
2,3c2,3行意味著第一個文件中的第2行和第3行需要更改,以匹配第二個文本文件中的第2行和第3行。
diff命令輸出符號說明?(diff Command Output Symbols explained)
Let’s briefly look at the various symbols encountered in the output.
讓我們簡要地看一下輸出中遇到的各種符號。
- The less than symbol indicates lines from the first line 小于符號表示從第一行開始的行
- The greater than symbol indicates lines from the second line 大于符號表示從第二行開始的行
a - Denotes that text was added to the file
c - Denotes that changes were made in the file
d - Indicates that the line was expunged or deleted
Let’s take a look at another example.
讓我們看另一個例子。
情況2:添加?(Case 2: Adding)
We have two text files:
我們有兩個文本文件:
The file?file 1.txt?has the following content.
文件1.txt具有以下內容。
Linux is a great operating system
It's free and opensource
It's light and stable
I would highly recommend it
file2.txt?has the following content.
file2.txt具有以下內容。
Linux is a great operating system
It's free and opensource
It's light and stable
Oh ! It can be installed on almost any PC hardware
I would highly recommend it
Use the diff command to compare both files.
使用diff命令比較兩個文件。
$ diff file1.txt file2.txtSample output
樣品輸出
From the output above,?3a4?implies that?after line 3 from the first file, another line needs to be added to match line 4 from the second file.
從上面的輸出中,?3a4表示在第一個文件的第3行之后,需要添加另一行以匹配第二個文件的第4行?。
情況3:刪除?(Case 3: Deletion)
Consider two files as below.
考慮以下兩個文件。
file3.txt?with the following content.
file3.txt具有以下內容。
Apples
Oranges
Mangoes
Peaches
Bananas
Grapes
And?file4.txt?which has the following content.
而file4.txt具有以下內容。
Apples
Oranges
Mangoes
Bananas
Grapes
Again, use the diff command to compare both files.
同樣,使用diff命令比較兩個文件。
$ diff file3.txt file4.txtSample output
樣品輸出
Here the output?4d3?means that delete the 4th line from the first file to sync up with the second file at line number 3.
這里的輸出4d3表示從第一個文件中刪除第4行,以與第2行的第二個文件同步。
結論?(Conclusion)
Linux diff command is a simple utility to compare two files. It’s useful in checking for the changes between two versions of a text file.
Linux diff命令是一個比較兩個文件的簡單實用程序。 在檢查文本文件的兩個版本之間的更改時很有用。
翻譯自:?Linux diff Command Examples - JournalDev
linux diff命令
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的linux diff命令_Linux diff命令示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Excel酷炫技能,批量修改工作表名称,
- 下一篇: undefined reference