在 Linux 下查找重复文件,常见方法和工具如下,按“从简单到专业”给你整理:
fdupes(推荐)# Debian / Ubuntu
sudo apt install fdupes
# CentOS / RHEL
sudo yum install fdupes
# Arch
sudo pacman -S fdupes
fdupes -r /path/to/dir
-r:递归子目录fdupes -rdN /path/to/dir
-d:删除重复-N:自动保留第一个,不交互rdfind按内容比对,速度快,支持按优先级保留。
sudo apt install rdfind
rdfind /path/to/dir
results.txtmd5sum 手动查适合脚本或没有安装权限时。
find /path -type f -exec md5sum {} \; | sort | uniq -w32 -d
解释:
md5sum:计算文件指纹sort:排序uniq -w32 -d:找重复 MD5查看具体文件:
find /path -type f -exec md5sum {} \; | sort | awk '{print $1}' | uniq -d
find /path -type f | sort | uniq -d
或:
find /path -type f | xargs -n1 basename | sort | uniq -d
如果你愿意,可以告诉我:
我可以给你更精确的命令。