预先对经比较的文件进行sort排序
comm
-12 就只显示在两个文件中都存在的行
-23 显示在近的文件中有出现而未在远的文件中无出现的行
comm -23 2.txt 1.txt #找出文件2中有,文件1中没有的行
diff
Linux diff command help and examples
[root@localhost test3]# diff log2014.log log2013.log
3c3 #####log2014.log和log20143log文件在第3行内容有所不同
< 2014-03
---
> 2013-03
8c8 #####log2014.log和log20143log文件在第8行内容有所不同
< 2013-07
---
> 2013-08
11,12d10 #####第一个文件比第二个文件多了第11和12行
< 2013-11
< 2013-12
- -y或--side-by-side 以并列的方式显示文件的异同之处。
- -W<宽度>或--width<宽度> 在使用-y参数时,指定栏宽。
[root@localhost test3]# diff log2014.log log2013.log -y -W 50
2013-01 2013-01
2013-02 2013-02
2014-03 | 2013-03 # "|"表示前后2个文件内容有不同
2013-04 2013-04
2013-05 2013-05
2013-06 2013-06
2013-07 2013-07
2013-07 | 2013-08
2013-09 2013-09
2013-10 2013-10
2013-11 < # "<"表示后面文件比前面文件少了1行内容
2013-12 <
[root@localhost test3]# diff log2013.log log2014.log -y -W 50
2013-01 2013-01
2013-02 2013-02
2013-03 | 2014-03
2013-04 2013-04
2013-05 2013-05
2013-06 2013-06
2013-07 2013-07
2013-08 | 2013-07
2013-09 2013-09
2013-10 2013-10
> 2013-11
> 2013-12 # ">"表示后面文件比前面文件多了1行内容
#谁尖谁多一条,箭头指向多的那条记录
output
左边几个点,文件几
"2,4c2,4" means: "Lines 2 through 4 in the first file need to be changed to match lines 2 through 4 in the second file." It then tells us what those lines are in each file:
Here, the output is telling us "After line 2 in the first file, a line needs to be added: line 3 from the second file." It then shows us what that line is.
Here, the output is telling us "You need to delete line 4 in the first file so that both files sync up同步 at line 3." It then shows us the contents of the line that needs to be deleted.