linux运维笔记——常用命令详解diff

1、diff
你可以把diff看成是linux上的文件比对工具

例子文件内容:
[root@localhost disks]# cat test1.txt 
a
b
c
d
[root@localhost disks]# cat test2.txt 
a
c
e
g

参数说明:
-q:只判断文件是否有差异

[root@localhost disks]# diff -q test1.txt  test2.txt 
Files test1.txt and test2.txt differ
[root@localhost disks]#

-c:显示文件全部内容,并标出差异的地方(适用于内容不多的文件)

[root@localhost disks]# diff -c test1.txt test2.txt 
*** test1.txt   2015-07-09 22:48:26.316626780 +0800
--- test2.txt   2015-07-09 22:48:52.681626749 +0800
***************
*** 1,4 ****
  a
- b
  c
! d
--- 1,4 ----
  a
  c
! e
! g
[root@localhost disks]# 

显示内容说明:
“ - ” 后面的文件比前面的文件少一行
“ +” 后面的文件比前面的文件多一行
“ ! ” 前后有差异

-y:以并列的方式显示差异

[root@localhost disks]# diff -y test1.txt test2.txt 
a                                                               a
b                                                             <
c                                                               c
d                                                             | e
                                                              > g
[root@localhost disks]# 

-W:指定宽度

[root@localhost disks]# diff -y test1.txt test2.txt -W 10
a       a
b   <
c       c
d   |   e
    >   g
[root@localhost disks]# 

显示内容说明:
“<”表示前面文件比后面文件多了1行内容
“>”表示后面文件比前面多了1行内容
“ | ”表示两个文件有差异
posted @ 2015-07-09 23:17  Jim.Deng  阅读(210)  评论(0编辑  收藏  举报