- 简介
- 第一章 - 关于 CD
- 第二章 - 基本命令
- Hack-7 Grep
- Hack-8 Grep 与正则表达式
- Hack-9 Find 命令
- Hak-10 重定向
- Hack-11 Join 命令
- Hack-12 Tr 命令
- Hack-13 Xargs 命令
- Hack-14 Sort 命令
- Hack-15 Uniq 命令
- Hack-16 Cut 命令
- Hack-17 Stat 命令
- Hack-18 Diff 命令
- Hack-19 Ac 命令
- Hack-20 让命令在后台执行
- Hack-21 Sed 替换基础
- Hack-22 Awk 简介
- Hack-23 VIM 基本入门
- Hack-24 Chmod 命令
- Hack-25 Tail -f -f
- Hack-26 Less 命令
- Hack-27 Wget 下载器
- 第三章 - SSH 技巧
- 第四章 - 日期设置
- 第五章 - PS* 介绍
- 第六章 - 压缩和打包
- 第七章 - 历史命令
- 第八章 - 系统任务管理
- 第九章 - 安装软件
- 第十章 - LAMP 套装
- 第十一章 - Bash 脚本
- 第十二章 - 系统性能监控
- 第十三章 - 额外的技巧
Hack-18 Diff 命令
Diff 命令
diff
是用来找不同的 :)
使用很简单:
diff [options] file1 file2
比如我又两个文件:
➤ cat diff1
1
2
a
➤ cat diff2
1
2
3
4
➤
然后我 diff
一下:
➤ diff diff1 diff2
3c3,4
< a # < 表示在第二个文件中缺失的部分
---
> 3 # > 表示在第一个文件中缺失的部分
> 4
➤
上面的结果中:
---
上面的内容是 diff1
文件的, ---
下面的内容则是 diff2
文件的内容。
那么 3c3,4
代表的是什么?
stackexchange 上面有人说可以忽略...
但是第三个答案说的就比较详细:
3d2
and5a5
denote line numbers affected and which actions were performed.d
stands for deletion,a
stands for adding (andc
stands for changing). the number on the left of the character is the line number in file1.txt, the number on the right is the line number in file2.txt. So3d2
tells you that the 3rd line in file1.txt was deleted and has the line number 2 in file2.txt (or better to say that after deletion the line counter went back to line number 2).5a5
tells you that the we started from line number 5 in file1.txt (which was actually empty after we deleted a line in previous action), added the line and this added line is the number 5 in file2.txt.
但其实知道了也没卵用... 不如 vimdiff
或者 diff -u
更直观。
扩展阅读:
本书简介:
- Linux 进阶技巧
- 巧妙的命令组合
- Bash 某些技巧
- 一共一百零一个(包括充数的)
- 最后有个奖励章(额外技巧)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论