diff 比较两个文件的不同

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

2       2

3     | 5

4       4

5       5

范例4  -c参数上下文输出格式

[root@localhost ~]# diff -c test1 test2

*** test1       2018-04-24 17:38:25.472481461 +0800

--- test2       2018-04-24 17:45:18.490482647 +0800

***************

*** 1,5 ****

! 1

 2

! 3

 4

 5

--- 1,6 ----

! 8

 2

! 5

 4

 5

+ 6

说明:!表示不同;+表示test2比test1多的行。

猜你喜欢

转载自www.cnblogs.com/joechu/p/8947651.html