Gop*_*ras -1 files file-comparison
$ cmp -s file1 file2
Run Code Online (Sandbox Code Playgroud)
对于以下情况,上述命令不会返回任何内容:
我尝试了以上所有情况,但我的unix系统不敏感。
-s
用于silent,它告诉cmp
不要输出任何内容\xc2\xb9,而只是在退出状态中反映文件是否相同,以便可以在if
shell语句中使用:
if cmp -s file1 file2; then\n echo same\nelse\n echo differ or error\nfi\n
Run Code Online (Sandbox Code Playgroud)\n\n或者:
\n\ncmp -s file1 file2 && rm file2\n
Run Code Online (Sandbox Code Playgroud)\n\n如果你想让它输出一些东西,删除-s
. 然后cmp
当文件不同时会输出一条消息,说明它们开始不同的位置。
\xc2\xb9 除外,当文件无法打开时,某些错误消息的实现除外,而不是当文件不同时。
\n