diff - compare files line by line 比较文件,从前往后比较
语法
SYNOPSIS
diff [OPTION]... FILES
- -q, --brief 文件 和 文件 不相同时,输出信息
[root@myhost ~]# diff -q test.txt test_1.txt
文件 tesk.txt 和 tesk_1.txt 不同
[root@myhost ~]# cat test.txt
name age
David 18
Jack 20
Lisa 32
[root@myhost ~]# cat test_1.txt
name age
David 18
Jack 20
Lisa 32
Bob 50
Michel 20
- -s, 如果条件成立,返回:文件 file.txt 和 filetest.txt 相同,如果不同忽略选项
- [root@myhost ~]# diff -s test.txt test_1.txt
4a5,6
> Bob 50
> Michel 20
- -c, -C NUM, --context[=NUM] ``
diff -C 2 test.txt test_1.txt
*** test.txt 2020-07-05 14:49:56.342000000 +0800
--- test_1.txt 2020-07-05 14:37:52.580000000 +0800
***************
*** 1,5 ****
name age
David 18
- Pack 22
Jack 20
Lisa 32
--- 1,6 ----
name age
David 18
Jack 20
Lisa 32
+ Bob 50
+ Michel 20
-u, -U NUM, --unified[=NUM] 较之-C选项
[root@myhost ~]# diff -U 2 test.txt test_1.txt
--- test.txt 2020-07-05 14:49:56.342000000 +0800
+++ test_1.txt 2020-07-05 14:37:52.580000000 +0800
@@ -1,5 +1,6 @@
name age
David 18
-Pack 22
Jack 20
Lisa 32
+Bob 50
+Michel 20
- -y, --side-by-side
[root@myhost ~]# diff -y test.txt test_1.txt
name age name age
David 18 David 18
Pack 22 <
Jack 20 Jack 20
Lisa 32 Lisa 32
> Bob 50
> Michel 20
- -W, --width=NUM 宽度
[root@myhost ~]# diff -y -W 34 test.txt test_1.txt
name age name age
David 18 David 18
Pack 22 <
Jack 20 Jack 20
Lisa 32 Lisa 32
> Bob 50
> Michel 20
- -a, --text treat all files as text