zoukankan      html  css  js  c++  java
  • 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行内容
    “ | ”表示两个文件有差异
  • 相关阅读:
    JavaScript实现Map、Reduce和Filter
    Javascript常用对象的属性和方法
    自己封装的Ajax
    JavaScript函数调用规则
    JavaScript模板引擎使用
    java 简单贪吃蛇
    java邮件发送(含附件)
    java 读写Oracle Blob字段
    java 连接飞信API
    非常棒的Java REST服务器栈
  • 原文地址:https://www.cnblogs.com/dengtr/p/5027362.html
Copyright © 2011-2022 走看看