返回介绍

Hack-18 Diff 命令

发布于 2025-03-08 17:38:20 字数 1856 浏览 0 评论 0 收藏 0

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 and 5a5 denote line numbers affected and which actions were performed. d stands for deletion, a stands for adding (and c 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. So 3d2 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文