在 OSX Lion 中使用命令行对文件进行重复数据删除

Sim*_*lGy 4 deduplication command-line

我使用的是 OSX 10.8.4,并且希望在 md5 哈希匹配的情况下删除单个平面目录中的重复文件。

我查找了几个答案,但没有一个对我有用,我认为这是因为终端版本之间的命令语法存在差异。

我尝试过的事情:

http://www.chriswrites.com/2012/02/how-to-find-and-delete-duplicate-files-in-mac-os-x/

使用脚本查找并删除 osx 中的重复文件

其中一些: http: //www.commandlinefu.com/commands/view/3555/find-duplicate-files-based-on-size-first-then-md5-hash#comment

这种方法感觉最接近:

find . -size 20 \! -type d -exec cksum {} \; | sort | tee /tmp/f.tmp | cut -f 1,2 -d ' ' | uniq -d | grep -hif - /tmp/f.tmp > duplicates.txt
Run Code Online (Sandbox Code Playgroud)

但我收到一个错误:grep: -: No such file or directory

经检查,/tmp/f.tmp确实存在。duplicates.txt 文件已创建,但为空。

如何删除这些文件的重复数据?

小智 5

基于哈希键查找重复项效果很好并且速度非常快。我经常使用下面的代码。如果您在 Mac 上运行此程序并遇到任何问题,请安装 GNU 工具并使用第二个版本。

Linux

find -not -empty -type f -printf "%s\n" | 查找 -not -empty -type f -printf "%s\n" | 排序-rn | uniq-d| xargs -I{} -n1 find -type f -size {}c -print0 | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | xargs -0 md5sum | xargs -0 md5sum | xargs -0 md5sum 排序| uniq -w32 --all-repeated=单独

Mac版

gfind -not -empty -type f -printf "%s\n" | gfind -not -empty -type f -printf "%s\n" | gfind -not -empty -type f -printf "%s\n" | 排序-rn | 古尼克-d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 gmd5sum | xargs -0 gmd5sum | 排序| Guniq -w32 --all-repeated=单独