搜索和删除具有不同名称的重复文件

Ces*_*ian 9 duplicate file-management files file-search

我的硬盘上存储了大量音乐收藏;浏览了一下,发现有些相册目录下有很多重复的文件。通常,副本存在于同一目录中的原始文件旁边。

通常格式为filename.mp3,重复文件为filename 1.mp3。有时可能会有多个重复文件,我不知道文件夹之间是否存在重复文件(例如专辑目录的重复文件)。

有什么方法可以扫描这些重复文件(例如,通过比较文件大小,或比较整个文件以检查它们是否相同),查看结果,然后删除重复文件?名称较长或修改/创建日期较近的名称通常是删除的目标。

有没有可以在 Linux 上执行此操作的程序?

Tob*_*ght 12

有这样一个程序,它叫做rdfind

SYNOPSIS
   rdfind [ options ] directory1 | file1 [ directory2 | file2 ] ...

DESCRIPTION
   rdfind  finds duplicate files across and/or within several directories.
   It calculates checksum only if necessary.  rdfind  runs  in  O(Nlog(N))
   time with N being the number of files.

   If  two  (or  more) equal files are found, the program decides which of
   them is the original and the rest are considered  duplicates.  This  is
   done  by  ranking  the  files  to each other and deciding which has the
   highest rank. See section RANKING for details.
Run Code Online (Sandbox Code Playgroud)

它可以删除重复项,或用符号或硬链接替换它们。


Tom*_*ych 12

哼。我刚刚开发了一个单线来列出所有重复项,因为一个问题被证明是这个问题的重复项。多么元。好吧,浪费它是一种耻辱,所以我会发布它,尽管rdfind听起来是一个更好的解决方案。

这至少具有成为“真正的”Unix 方式的优势;)

find -name '*.mp3' -print0 | xargs -0 md5sum | sort | uniq -Dw 32
Run Code Online (Sandbox Code Playgroud)

中断管道:

find -name '*.mp3' -print0 在从当前目录开始的子树中查找所有 mp3 文件,打印名称以 NUL 分隔。

xargs -0 md5sum 读取 NUL 分隔的列表并计算每个文件的校验和。

你知道做什么sort

uniq -Dw 32 比较已排序行的前 32 个字符并仅打印具有相同散列的字符。

所以你最终会得到一个所有重复项的列表。然后,您可以手动将其减少到要删除的那些,删除散列,并将列表通过管道传输到rm.