Diff 命令
diff
是用来找不同的 :)
使用很简单:
diff [options] file1 file2
比如我又两个文件:
➤ cat diff1
1
2
a
➤ cat diff2
1
2
3
4
➤
然后我diff
一下:
➤ diff diff1 diff2
3c3,4
< a # < 表示在第二个文件中缺失的部分
---
> 3 # > 表示在第一个文件中缺失的部分
> 4
➤
上面的结果中:
—-
上面的内容是diff1
文件的, —-
下面的内容则是diff2
文件的内容.
那么3c3,4
代表的是什么?
stackexchange上面有人说可以忽略…
但是第三个答案说的就比较详细:
3d2
and5a5
denote line numbers affected and which actions were performed.d
stands for deletion,a
stands for adding (andc
stands for changing). the number on the left of the character is the line number in file1.txt, the number on the right is the line number in file2.txt. So3d2
tells you that the 3rd line in file1.txt was deleted and has the line number 2 in file2.txt (or better to say that after deletion the line counter went back to line number 2).5a5
tells you that the we started from line number 5 in file1.txt (which was actually empty after we deleted a line in previous action), added the line and this added line is the number 5 in file2.txt.
但其实知道了也没卵用… 不如vimdiff
或者diff -u
更直观.
扩展阅读: