首页 > 其他 > 详细

diff 比较两个文件的不同

时间:2018-04-26 00:32:48      阅读:192      评论:0      收藏:0      [点我收藏+]

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多的行。

diff 比较两个文件的不同

原文:https://www.cnblogs.com/joechu/p/8947651.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!