如何在单独的目录中查找没有重复的文件

Red*_*dro 5 filesystem backup files duplicate-files

我有一个旧的文件备份。在我当前的Documents目录中,很多这些文件以不同的名称存在于不同的位置。我正在尝试找到一种方法来显示备份中存在哪些目录中存在的Documents文件,最好是漂亮且具有 GUI 特征的文件,以便我可以轻松浏览大量文档。

当我搜索这个问题时,很多人都在寻找相反的方法。有像FSlintDupeGuru这样的工具,但它们显示重复。没有反转模式。

Ron*_*Ron 5

如果您准备使用 CLI,以下命令应该适合您:

diff --brief -r backup/ documents/
Run Code Online (Sandbox Code Playgroud)

这将显示每个文件夹独有的文件。如果你愿意,你也可以忽略文件名大小写--ignore-file-name-case

举个例子:

ron@ron:~/test$ ls backup/
file1  file2  file3  file4  file5
ron@ron:~/test$ ls documents/
file4  file5  file6  file7  file8
ron@ron:~/test$ diff backup/ documents/
Only in backup/: file1
Only in backup/: file2
Only in backup/: file3
Only in documents/: file6
Only in documents/: file7
Only in documents/: file8
ron@ron:~/test$ diff backup/ documents/ | grep "Only in backup"
Only in backup/: file1
Only in backup/: file2
Only in backup/: file3
Run Code Online (Sandbox Code Playgroud)

此外,如果您只想在文件不同时报告(而不报告实际的“差异”),您可以使用该--brief选项,如下所示:

ron@ron:~/test$ cat backup/file5 
one
ron@ron:~/test$ cat documents/file5
ron@ron:~/test$ diff --brief backup/ documents/
Only in backup/: file1
Only in backup/: file2
Only in backup/: file3
Files backup/file5 and documents/file5 differ
Only in documents/: file6
Only in documents/: file7
Only in documents/: file8
Run Code Online (Sandbox Code Playgroud)

有几种视觉差异工具meld可以做同样的事情。您可以meld通过以下方式从 Universe 存储库安装:

sudo apt-get install meld
Run Code Online (Sandbox Code Playgroud)

并使用其“目录比较”选项。选择要比较的文件夹。选择后,您可以并排比较它们:

在此处输入图片说明

fdupes是一个查找重复文件的优秀程序,但它不会列出非重复文件,而这正是您要查找的。但是,我们可以列出不在文件fdupes使用的组合输出findgrep

以下示例列出了backup.

ron@ron:~$ tree backup/ documents/
backup/
??? crontab
??? dir1
?   ??? du.txt
??? lo.txt
??? ls.txt
??? lu.txt
??? notes.txt
documents/
??? du.txt
??? lo-renamed.txt
??? ls.txt
??? lu.txt

1 directory, 10 files
ron@ron:~$ fdupes -r backup/ documents/ > dup.txt
ron@ron:~$ find backup/ -type f | grep -Fxvf dup.txt 
backup/crontab
backup/notes.txt
Run Code Online (Sandbox Code Playgroud)