给定文件路径,如何找到该文件的每个副本?

con*_*use 0 search files

我知道诸如rdfind或 之类的程序fdupes类的程序。他们解决了类似但更复杂的问题。

给定一个文件路径和一个目录,我想递归地搜索该目录以查找该文件的每个副本 - 无论是在其他名称、权限还是所有权下。

例如,如果我这样做了rdfind needle.file haystack/,它还会发现除此之外的文件needle.file仅在haystack.

我可以过滤 的输出rdfind,但是如果haystack/很大,这会做很多不必要的工作。

应该有一个命令行应用程序,因为我打算在脚本/cron-job 中使用它。

Pan*_*nki 5

一个简单的方法:

  • 获取md5sum目标文件的,将其存储在变量中
  • 获取文件的大小,存储在变量中
  • 用于find运行md5sum在所有相同大小的文件上
  • grepfind我们的目标 MD5 哈希值的输出
target_hash=$(md5sum needle.file | awk '{ print $1 }')
target_size=$(du -b needle.file | awk '{ print $1 }')
find haystack/ -type f -size "$target_size"c -exec md5sum {} \; | grep $target_hash
Run Code Online (Sandbox Code Playgroud)