每天一个 Linux 命令(36): diff 命令

栏目: Linux · 发布时间: 7年前

内容简介:diff 命令是 linux上非常重要的工具,用于比较文件的内容,特别是比较两个版本不同的文件以找到改动的地方。diff在命令行中打印每一个行的改动。最新版本的diff还支持二进制文件。

diff 命令是 linux上非常重要的工具,用于比较文件的内容,特别是比较两个版本不同的文件以找到改动的地方。diff在命令行中打印每一个行的改动。最新版本的diff还支持二进制文件。diff程序的输出被称为补丁 (patch),因为 Linux 系统中还有一个patch程序,可以根据diff的输出将a.c的文件内容更新为b.c。diff是svn、cvs、git等版本控制 工具 不可或缺的一部分。

1.命令格式:

2.命令功能:

diff命令能比较单个文件或者目录内容。如果指定比较的是文件,则只有当输入为文本文件时才有效。以逐行的方式,比较文本文件的异同处。如果指定比较的是目录的的时候,diff 命令会比较两个目录下名字相同的文本文件。列出不同的二进制文件、公共子目录和只在一个目录出现的文件。

3.命令参数:

4.使用实例:

实例1:比较两个文件

命令:

输出:

说明:

上面的“3c3”和“8c8”表示log2014.log和log20143log文件在3行和第8行内容有所不同;”11,12d10″表示第一个文件比第二个文件多了第11和12行。

diff 的normal 显示格式有三种提示:

实例2:并排格式输出

命令:

输出:

说明:

实例3:上下文输出格式

命令:

输出:

说明:

这种方式在开头两行作了比较文件的说明,这里有三中特殊字符:

实例4:统一格式输出

命令:

输出:

说明:

它的第一部分,也是文件的基本信息:

“—“表示变动前的文件,”+++”表示变动后的文件。

第二部分,变动的位置用两个@作为起首和结束。

前面的”-1,12″分成三个部分:减号表示第一个文件(即log2014.log),”1″表示第1行,”12″表示连续12行。合在一起,就表示下面是第一个文件从第1行开始的连续12行。同样的,”+1,10″表示变动后,成为第二个文件从第1行开始的连续10行。

实例5:比较文件夹不同

命令:

输出:

说明:

实例6:比较两个文件不同,并生产补丁

命令:

输出:

说明:

实例7:打补丁

命令:

输出:

说明:

本系列文章:

每天一个 Linux 命令(1):ls命令
每天一个 Linux 命令(2):cd命令
每天一个 Linux 命令(3):pwd命令
每天一个 Linux 命令(4):mkdir命令
每天一个 Linux 命令(5):rm 命令
每天一个 Linux 命令(6):rmdir 命令
每天一个 Linux 命令(7):mv命令
每天一个 Linux 命令(8):cp 命令
每天一个 Linux 命令(9):touch 命令
每天一个 Linux 命令(10):cat 命令
每天一个 Linux 命令(11):nl 命令
每天一个 Linux 命令(12):more 命令
每天一个 Linux 命令(13):less 命令
每天一个 Linux 命令(14):head 命令
每天一个 Linux 命令(15):tail 命令
每天一个 Linux 命令(16):which命令
每天一个 Linux 命令(17):whereis 命令
每天一个 Linux 命令(18):locate 命令
每天一个 Linux 命令(19):find 命令概览
每天一个 Linux 命令(20):find命令之exec
每天一个 Linux 命令(21):find命令之xargs
每天一个 Linux 命令(22):find 命令的参数详解
每天一个 Linux 命令(23):Linux 目录结构
每天一个 Linux 命令(24):Linux 文件类型与扩展名
每天一个 Linux 命令(25):Linux 文件属性详解
每天一个 Linux 命令(26):用 SecureCRT 来上传和下载文件
每天一个 Linux 命令(27):linux chmod 命令
每天一个 Linux 命令(28):tar 命令
每天一个 Linux 命令(29): chgrp 命令
每天一个 Linux 命令(30): chown 命令
每天一个 Linux 命令(31): /etc/group 文件详解
每天一个 Linux 命令(32):gzip 命令
每天一个 Linux 命令(33):df 命令
每天一个 Linux 命令(34): du 命令
每天一个 Linux 命令(35): ln 命令


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Designing Data-Intensive Applications

Designing Data-Intensive Applications

Martin Kleppmann / O'Reilly Media / 2017-4-2 / USD 44.99

Data is at the center of many challenges in system design today. Difficult issues need to be figured out, such as scalability, consistency, reliability, efficiency, and maintainability. In addition, w......一起来看看 《Designing Data-Intensive Applications》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具