用校验和找出重复文件

即使文件名不同,也能找出内容完全相同的重复文件。

macOS文件重复文件低风险
运行 find 加 md5 的组合命令,即可列出所有存在相同副本的文件路径。

01命令

命令
$ cd ~/Downloads && find . -type f -not -name ".DS_Store" -exec md5 -r {} + | sort | awk '{c[$1]++; f[$1]=$2} END {for (h in c) if (c[h]>1) print f[h]}'

02作用说明

md5 -r 会输出「校验和 文件名」,按校验和排序后相同内容自然相邻,awk 负责对每个重复组输出一个路径。它只能找出字节级完全相同的文件,不同时间保存或不同画质的照片不算重复。建议先把结果导出成 duplicates.txt 查看确认后再删除,每组保留一份。

03风险

风险低风险
!注意: 相同哈希代表内容相同,但删除前务必核对列表——列表包含每份副本,每组记得留一份。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • shasum – Calculate SHA checksums
    ss64.com · technical · 2026-09-17
    依据: Checksum tools (md5/shasum) produce identical hashes for identical content — the basis of duplicate detection.
  • find – Walk a file hierarchy
    ss64.com · technical · 2026-09-17
    依据: find -type f -exec runs the checksum tool over every file in the tree in batches.

最后验证: 2026-09-18 · 分类: 文件与文件夹

06相关方案