zoukankan      html  css  js  c++  java
  • 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多的行。

  • 相关阅读:
    图解C/C++多级指针与多维数组
    排序---选择排序
    排序---插入排序
    排序---希尔排序
    Merge Two Sorted Lists
    Remove Nth Node From End of List
    如何阅读Django文档?
    机器学习 第一章 绪论 笔记
    python工程实践·笔记
    Python后端开发面经
  • 原文地址:https://www.cnblogs.com/joechu/p/8947651.html
Copyright © 2011-2022 走看看