我的目录中有许多文件,我想检查它们是否唯一。为简单起见,假设我有三个文件:foo.txt
,bar.txt
和baz.txt
。如果运行此循环,则将彼此进行检查:
$ for f in ./*; do for i in ./*; do diff -q "$f" "$i"; done; done
Files bar.txt and baz.txt differ
Files bar.txt and foo.txt differ
Files baz.txt and bar.txt differ
Files baz.txt and foo.txt differ
Files foo.txt and bar.txt differ
Files foo.txt and baz.txt differ
对于我要处理的数百个文件,这将变得非常难以阅读;最好列出确实匹配的文件,然后我可以快速查看列表并确保文件仅匹配自己。从联机帮助页来看,我认为该-s
选项可以完成此任务:
$ for f in ./*; do for i in ./*; do diff -s "$f" "$i"; done; done
Files bar.txt and bar.txt are identical
Files baz.txt and baz.txt are identical
Files foo.txt and foo.txt are identical
...但是,实际上,它还会打印出所有不同文件的全部内容。有什么办法可以抑制这种行为,所以我只能得到上面的行为?
另外,还有其他工具可以完成此任务吗?