用途

按行比较文件差异,也可以比较目录

用法

diff [OPTION]... FILES

常用选项

-i --ignore-case

忽略大小写

--ignore-file-name-case

忽略文件名大小写

--no-ignore-file-name-case

文件名区分大小写

-E --ignore-tab-expansion

忽略tab字符

-b --ignore-space-change

忽略空格

-w --ignore-all-space

忽略所有空格

-B --ignore-blank-lines

忽略空白行

-I RE --ignore-matching-lines=RE

过滤匹配的行

--strip-trailing-cr

去掉行尾回车符

-a --text

所有文件内容当做文本

-c -C NUM --context[=NUM]

(Output NUM (default 3) lines of copied context.)

-u -U NUM --unified[=NUM]

(Output NUM (default 3) lines of unified context.)

--label LABEL

使用LABEL代替文件名

-p --show-c-function

显示差异行所在文件

-F RE --show-function-line=RE

(Show the most recent line matching RE.)

-q --brief

直接输出结果是否有差异

-e --ed

(Output an ed script.)

--normal

(Output a normal diff.)

-n --rcs

(Output an RCS format diff.)

-y --side-by-side

同时输出2个文件的内容,对照显示

-W NUM --width=NUM

(Output at most NUM (default 130) print columns.)

--left-column

左边输出完整内容,右边只输出差异

--suppress-common-lines

只输出差异行

-D NAME --ifdef=NAME

(Output merged file to show ‘#ifdef NAME’ diffs.)

--GTYPE-group-format=GFMT

(Similar, but format GTYPE input groups with GFMT.)

(GTYPE is LTYPE or ‘changed’.)

--line-format=LFMT

(Similar, but format all input lines with LFMT.)

--LTYPE-line-format=LFMT

(Similar, but format LTYPE input lines with LFMT.)

(LTYPE is ‘old’, ‘new’, or ‘unchanged’.)

-l --paginate

分页显示

-t --expand-tabs

输出时,tab字符换成空格

-T --initial-tab

(Make tabs line up by prepending a tab.)

-r --recursive

(Recursively compare any subdirectories found.)

-N --new-file

(Treat absent files as empty.)

--unidirectional-new-file

(Treat absent first files as empty.)

-s --report-identical-files

(Report when two files are the same.)

-x PAT --exclude=PAT

(Exclude files that match PAT.)

-X FILE --exclude-from=FILE

(Exclude files that match any pattern in FILE.)

-S FILE --starting-file=FILE

(Start with FILE when comparing directories.)

--from-file=FILE1

(Compare FILE1 to all operands. FILE1 can be a directory.)

--to-file=FILE2

(Compare all operands to FILE2. FILE2 can be a directory.)

--horizon-lines=NUM

(Keep NUM lines of the common prefix and suffix.)

-d --minimal

(Try hard to find a smaller set of changes.)

--speed-large-files

(Assume large files and many scattered small changes.)

-v --version

输出程序版本信息

--help

显示帮助信息

实践

1 比较2个文件

# 显示所有
diff -y dir1/friend.php friend.php # 只显示差异
diff -y --suppress-common-lines dir1/friend.php friend.php # 只显示左边完整内容,右边只显示差异内容
diff -y --left-column dir1/friend.php friend.php

擦参考资料

【1】man diff

N天学习一个linux命令之diff的更多相关文章

  1. N天学习一个Linux命令之帮助命令:man

    前言 工作中每天都在使用常用的命令和非常用的命令,忘记了用法或者参数,都会bing一下,然后如此循环.一直没有真正的系统的深入的去了解命令的用法,我决定打破它.以前看到有人,每天学习一个linux命令 ...

  2. N天学习一个Linux命令之free

    用途 查看系统内存(物理/虚拟/缓存/共享)使用情况 用法 free [-b | -k | -m | -g | -h] [-o] [-s delay ] [-c count ] [-a] [-t] [ ...

  3. N天学习一个linux命令之ping

    用途 检测主机是否可到达,也就是说,目标主机是否可以联网,还可以用于检测网速.通过发送ICMP ECHO_REQUEST数据包检测. 用法 ping [options] destination 常用选 ...

  4. N天学习一个linux命令之kill

    用途 用于终止进程 用法 kill [-s signal|-p] [--] pid... kill -l [signal] 说明 1.默认发送信号15(请求终止进程,程序可以捕获,操作系统会杀死没有对 ...

  5. N天学习一个linux命令之du

    用途 统计文件或者目录占用硬盘空间大小 用法 du [OPTION] [FILE]du [OPTION] --files0-from=F 常用参数 -a, --all统计所有文件,不仅仅是目录 -b, ...

  6. N天学习一个linux命令之scp

    用途 通过ssh通道,不同主机之间复制文件 用法 scp [options] [user@host:]file1 [user2@host2:]file2 常用参数 -1使用 ssh 1协议 -2使用s ...

  7. 每天学习一个Linux命令-目录

    在工作中总会零零散散使用到各种Linux命令,从今天开始详细的学习一下linux常用命令,坚持每天一个命令,学习的主要参考资料为: 1.竹子-博客(https://www.cnblogs.com/pe ...

  8. 每天一个linux命令(49)--diff命令

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

  9. N天学习一个linux命令之umask

    前言 umask不是linux命令,而是shell内置的指令,俗称用户权限掩码,用于对用户创建的文件和目录设置默认权限.默认的权限掩码是0022,也就是说新创建的文件权限是0644,新创建的目录权限是 ...

随机推荐

  1. BZOJ 3456 NTT图的计数 容斥

    思路: RT 懒得写了 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm&g ...

  2. 【BZOJ1483】[HNOI2009]梦幻布丁(平衡树启发式合并+并查集)

    题目: BZOJ1483 分析: (这题码了一下午,码了近250行,但是意外跑的比本校各位神仙稍快,特写博客纪念) 首先能看出一个显然的结论:颜色段数只会变少不会变多. 我们考虑用并查集维护区间,对于 ...

  3. Laravel (5.5.33) 加载过程(二)

    本次说明代码 /* |-------------------------------------------------------------------------- | Turn On The ...

  4. html5——css选择器

    复习 div>p: 子代 div+p:div后面相邻的第一个p div~p: div后面所有的兄弟p 属性选择器 标志:[]:区别于id选择器:#,区别于类名选择器:. 特殊符号:^:开头    ...

  5. Json——转义符

    C#后台直接输出Json字符串需要反斜杠“\” context.Response.Write("[{\"Name\": \"wqx\", \" ...

  6. 使用jQuery的toggle()方法对HTML标签进行显示、隐藏操作

    这是一个示例: <html> <head> <script type="text/javascript" src="https://code ...

  7. Linux 查询PID和端口号

    https://www.cnblogs.com/understander/p/5546458.html

  8. C# 获得Properties下的定义的资源

    var str1 = Properties.Resources.ResourceManager.GetObject("String1", null); string url = S ...

  9. jenkins配置邮件通知

    参考: https://www.cnblogs.com/imyalost/p/8781759.html 谢谢大佬~

  10. JSON,对象..的数据格式

    [此案例为自动产生的随机数] 对象: {a1:180,a2:721, a3:574} 序列化传值:将对象转化为Json字符串 public ActionResult Val2() { Random r ...