使用 cmp 命令比较目录列表
如果使用 cmp 命令比较两个目录列表(ls dir1 和 ls dir2),它会比较两个目录中的文件内容还是仅比较两个目录中的文件名?
If cmp command is used to compare two directory listings (ls dir1 and ls dir2), will it compare the contents of the files in both directories or just the file names in both directories?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用两个命令来检查文件之间的差异:
cmp
使用字节比较,而diff
使用行比较。因此,
diff
更适合文本文件,如以下示例所示:cmp
结果:diff
结果:如您所见,它是非常清楚地看到哪些行仅存在于一个或另一个文件中。
如果您只想检查两个文件是否相等,您可以检查校验和(输出包含校验和、字节数和文件名):
There are two commands you can use for checking the differences between files:
cmp
uses byte comparison, whilediff
uses line comparison.As a result,
diff
is better for textfiles, as you can see in following examples:cmp
result:diff
result:As you see, it's very clear to see which lines only exist in one or the other file.
In case you just want to check if two files are equal or not, you might check the checksum (output contains checksum, number of bytes and filename):