如果可以在命令行上使用一系列命令来解决问题,那么对我来说这比编写脚本更好
答案1
for x in *; do for y in *; do [ "$x" = "$y" ] && continue; cmp -s "$x" "$y" && echo Same: "$x" and "$y"; done; done|head -1
或者,为了可读性而进行一些分解:
for x in *
do
for y in *
do
[ "$x" = "$y" ] && continue
cmp -s "$x" "$y" && echo Same: "$x" and "$y"
done
done | head -1
这head
只是为了保持镜像向下报告(“a = b”和“b = a”)。
答案2
find . -type f -exec md5sum "{}" \; | awk 'seen[$1] { print "Duplicate file "$2" with hash "$1" at "seen[$1]" } ! seen[$1] {seen[$1]=$2}'