文件不同 diff --brief XX YY

文件不同

diff --brief XX YY

文件不同 --哪些位置

diff -c XX YY

9.diff命令

diff命令用于比较多个文本文件的差异,格式为“diff [参数] 文件”。

在使用diff命令时,不仅可以使用--brief参数来确认两个文件是否不同,还可以使用-c参数来详细比较出多个文件的差异之处,这绝对是判断文件是否被篡改的有力神器。例如,先使用cat命令分别查看diff_A.txt和diff_B.txt文件的内容,然后进行比较:

[root@linuxprobe ~]# cat diff_A.txt
Welcome to linuxprobe.com
Red Hat certified
Free Linux Lessons
Professional guidance
Linux Course
[root@linuxprobe ~]# cat diff_B.txt
Welcome tooo linuxprobe.com

Red Hat certified
Free Linux LeSSonS
////////.....////////
Professional guidance
Linux Course

接下来使用diff --brief命令显示比较后的结果,判断文件是否相同:

[root@linuxprobe ~]# diff --brief diff_A.txt diff_B.txt
Files diff_A.txt and diff_B.txt differ

最后使用带有-c参数的diff命令来描述文件内容具体的不同:

[root@linuxprobe ~]# diff -c diff_A.txt diff_B.txt
*** diff_A.txt 2017-08-30 18:07:45.230864626 +0800
--- diff_B.txt 2017-08-30 18:08:52.203860389 +0800
***************
*** 1,5 ****
! Welcome to linuxprobe.com
Red Hat certified
! Free Linux Lessons
Professional guidance
Linux Course
--- 1,7 ----
! Welcome tooo linuxprobe.com
!
Red Hat certified
! Free Linux LeSSonS
! ////////.....////////
Professional guidance
Linux Course

猜你喜欢

转载自www.cnblogs.com/xuanbjut/p/11924396.html
yy
xx