在 Linux 下查找重复文件,常见做法有命令行工具和脚本方式,下面按实用程度给你总结。
# Debian / Ubuntu
sudo apt install fdupes
# CentOS / Rocky / Alma
sudo yum install fdupes
# Arch
sudo pacman -S fdupes
fdupes -r /path/to/dir
-r:递归子目录fdupes -rdN /path/to/dir
-d:删除重复-N:自动保留第一个,不交互sudo apt install rdfind
rdfind /path/to/dir
results.txtfind /path -type f -exec md5sum {} \; | \
sort | \
uniq -w32 -d
说明:
md5sum:计算文件指纹uniq -w32:比较前 32 字符(md5)查看具体文件:
find /path -type f -exec md5sum {} \; | \
sort | awk '{print $1}' | uniq -d
find /path -type f -printf "%s %p\n" | \
sort | uniq -w1 -d
适合先缩小范围。
fdupes 默认视为重复find /path -type f -name "*.jpg" -exec fdupes {} +
如果你愿意,可以告诉我:
我可以给你更精确的命令。