1.命令功能
diff 逐行比较文件内容,并输出文件差异。
2.语法格式
diff option file1 file2
diff 选项 文件1 文件2
参数说明
参数
参数说明
-y
以并列方式显示文件的异同之处
-W
在使用-y时,指定显示跨度
-c
上下文显示输出格式
-u
统一格式输出
3.使用范例
范例1 diff 不接任何参数
[root@localhost ~]# cat test1
1
2
3
4
5
[root@localhost ~]# cat test2
8
2
5
4
5
[root@localhost ~]# diff test1 test2
1c1
< 1
---
> 8
3c3
< 3
---
> 5
范例2 并排显示差异
[root@localhost ~]# diff -y test1 test2
1 | 8
2 2
3 | 5
4 4
5 5
范例3 并排显示差异,并指定宽度
[root@localhost ~]# diff -y -W 20 test1 test2
1 | 8