如果已知两个文本文件的内容非常相似,但是希望确定二者之间的差别或哪个文件已被更改,请执行以下操作:
首先,运行 ll,查看日期和时间字段,了解上次保存文件的日期和时间。例如:
-rw-r--r-- 1 jim users 1759 3 月 17 日 15:53 test1
-rw-r--r-- 1 jim users 2130 3 月 17 日 15:47 test2
test1 的保存时间晚于 test2,因为它的时间较新(大小亦有所改变)。
通过运行 diff 命令,可以确定 test1 和 test2 之间的差别:
diff(1)
例如,如果 test1 的内容是:
You are in a maze of twisty little passages which are all alike. |
而 test2 的内容是:
You are in a maze of twisty little passages which are all different. |
此命令将按行号指出找到的差别,并用“<”和“>”指出存在差别的文件:
3c3 相关的行号
< which are all alike. test1 的版本
---
> which are all different. test2 的版本
注意,diff 命令指出:如果删除标为“<”的一行,并添加标为“>”的另一行,则两个文件将相同。