概述查找和替换重复文件是大多数计算机用户的常见需求。查找和删除重复文件是一项需要时间和耐心的大量工作。如果你使用的系统是windows系统,DuplicateFilesDeleter可以帮你轻松解决问题。如果您使用的是Linux系统,则不必担心,查找重复文件也是一件非常容易的事情,这就是fdupes实用程序。什么是fdupes?Fdupes是由AdrianLopez使用C编程语言编写的Linux实用程序,在MIT许可下发布。该应用程序能够在给定的一组目录和子目录中查找重复文件。Fdupes通过比较文件的MD5签名,然后逐字节比较来识别重复项。Fdupes可以传递许多选项来列出、删除和替换带有重复文件硬链接的文件。比较顺序为:大小比较>部分MD5签名比较>完整MD5签名比较>逐字节比较。在Linux上安装fdupes在基于CentOS/RHEL和Fedora的系统上,您需要打开epel存储库来安装fdupes包。#yuminstallfdupes#dnfinstallfdupes[centos8]注意:从centos8开始,默认包管理器yum被dnf取代。如何使用fdupes命令?$fdupes-husage:fdupes[options]directory...-r--recurseforeachgivendirectoryfollowsubdirectoriesencounteredwithin-R--recurse:Foreachdirectorygivenafterthisoption,followsubdirectoryencounteredwithin(notethe':'在选项末尾,手册页了解更多详细信息)-s--symlinks遵循符号链接-H--hardlinks通常,当两个或多个文件指向同一磁盘区域时,它们被认为是不同的;此选项将更改-n--noempty排除零长度文件-A--nohidden排除隐藏文件-f--omitfirst忽略每组匹配项中的第一个文件-1--sameline在一行中列出每组匹配项-S--size显示重复文件的大小-m--summarize总结重复信息-q--quiet隐藏进度指示器-d--delete提示用户保留所有文件并删除else;重要:在特定情况下,将此选项与-s或--symlinks一起使用时,或者多次指定特定目录时,数据可能会丢失;有关更多信息,请参阅fdupes文档-N--noprompt和--delete,保留每个组重复的第一个文件,并在不提示用户的情况下删除其余文件-v--version显示fdupes版本-h--help显示此帮助消息显示:mkdir/home/dba/test&&cd/home/dba/test&&for我在{1..15};做echo"helloworld">file${i}.txt;done运行上述命令后,让我们使用ls命令验证是否创建了重复文件[root@192_168_209_128test]#ls-ltotal60-rw-r--r--1rootroot12Apr1023:02file10.txt-rw-r--r--1rootroot12Apr1023:02file11.txt-rw-r--r--1rootroot12Apr1023:02file12.txt-rw-r--r--1rootroot12Apr1023:02file13.txt-rw-r--r--1rootroot12Apr1023:02file14.txt-rw-r--r--1rootroot12Apr1023:02file15.txt-rw-r--r--1rootroot12Apr1023:02file1.txt-rw-r--r--1rootroot12Apr1023:02file2.txt-rw-r--r--1rootroot12Apr1023:02file3.txt-rw-r--r--1rootroot12Apr1023:02file4.txt-rw-r--r--1rootroot12Apr1023:02file5.txt-rw-r--r--1rootroot12Apr1023:02file6.txt-rw-r--r--1rootroot12Apr1023:02file7.txt-rw-r--r--1rootroot12Apr1023:02file8.txt-rw-r--r--1rootroot12Apr1023:02file9.txt上面的脚本创建15个文件,即file1.txt、file2.txt...file15.txt,每个文件包含相同的数据,即“helloworld"2.现在在文件夹test中搜索重复文件。[root@192_168_209_128测试]#fdupes/home/dba/test/home/dba/test/file1.txt/home/dba/test/file2.txt/home/dba/test/file3.txt/home/dba/test/file4.txt/home/dba/test/file5.txt/home/dba/test/file6.txt/home/dba/test/file7.txt/home/dba/test/file8.txt/home/dba/test/file9.txt/home/dba/test/file10.txt/home/dba/test/file11.txt/home/dba/test/file12.txt/home/dba/test/file13.txt/home/dba/test/file14.txt/home/dba/test/file15.txt3,使用-r选项递归搜索每个目录(包括其子目录)下的重复项。它递归地搜索所有文件和文件夹,根据文件和文件夹的数量,扫描重复项需要一些时间。同时,你会看到终端的总进度,像这样。[root@192_168_209_128test]#fdupes-r/homeProgress[2544/3628]70%4.使用-S选项查看在文件夹中找到的重复项的大小。[root@192_168_209_128test]#fdupes-S/home/dba/test12byteseach:/home/dba/test/file1.txt/home/dba/test/file2.txt/home/dba/test/file3.txt/home/dba/test/file4.txt/home/dba/test/file5.txt/home/dba/test/file6.txt/home/dba/test/file7.txt/home/dba/test/file8.txt/home/dba/test/file9.txt/home/dba/test/file10.txt/home/dba/test/file11.txt/home/dba/test/file12.txt/home/dba/test/file13.txt/home/dba/test/file14.txt/home/dba/test/file15.txt5.可以同时使用-S和-r选项查看遇到的每个目录和子目录的重复文件大小,如下:[root@192_168_209_128test]#fdupes-Sr/home/dba/test|more315byteseach:/home/dba/test/etc/firewalld/zones/public.xml/home/dba/test/etc/firewalld/zones/public。xml.old39字节每个:/home/dba/test/etc/subuid-/home/dba/test/etc/subgid-4364字节每个:/home/dba/test/etc/vmware-tools/poweroff-vm-default/home/dba/test/etc/vmware-tools/poweron-vm-default/home/dba/test/etc/vmware-tools/resume-vm-default/home/dba/test/etc/vmware-tools/suspend-vm-default984字节每个:/home/dba/test/etc/sane.d/dc210.conf/home/dba/test/etc/sane.d/dc240.conf每个13字节:/home/dba/test/etc/sane.d/s9036.conf/home/dba/test/etc/sane.d/nec.conf每个1字节:/home/dba/test/etc/at.deny/home/dba/test/etc/resolv.conf.save104字节每个:/home/dba/test/etc/dconf/db/gdm/home/dba/test/etc/dconf/db/site/home/dba/test/etc/dconf/db/local4504字节每个:--更多--6。除了递归搜索一个文件夹或所有文件夹外,您还可以根据需要选择两个文件夹或三个文件夹。更不用说,您可以使用选项-S和/或-r。$fdupes/home/avi/Desktop//home/avi/Templates/7.要在保留副本的同时删除重复文件,您可以使用选项“-d”。使用此选项时应格外小心,否则您可能最终会丢失必要的文件/数据,并注意该过程不可恢复。[root@192_168_209_128test]#fdupes-d/home/dba/test[1]/home/dba/test/file1.txt[2]/home/dba/test/file2.txt[3]/home/dba/test/file3.txt[4]/home/dba/test/file4.txt[5]/home/dba/test/file5.txt[6]/home/dba/test/file6.txt[7]/home/dba/test/file7.txt[8]/home/dba/test/file8.txt[9]/home/dba/test/file9.txt[10]/home/dba/test/file10.txt[11]/home/dba/test/file11.txt[12]/home/dba/test/file12.txt[13]/home/dba/test/file13.txt[14]/home/dba/test/file14.txt[15]/home/dba/test/file15.txtSet1of1,preservefiles[1-15,all]:你可能会注意到列出了所有重复项并提示删除,一个一个或一个范围或一次删除所有.您可以选择如下范围来删除特定范围的文件文件。设置1个,共1个,保留文件[1-15,全部]:2-15[-]/home/dba/test/file1.txt[+]/home/dba/test/file2.txt[-]/home/dba/test/file3.txt[-]/home/dba/test/file4.txt[-]/home/dba/test/file5.txt[-]/home/dba/test/file6.txt[-]/home/dba/test/file7.txt[-]/home/dba/test/file8.txt[-]/home/dba/test/file9.txt[-]/home/dba/test/file10.txt[-]/home/dba/test/file11.txt[-]/home/dba/test/file12.txt[-]/home/dba/test/file13.txt[-]/home/dba/test/file14.txt[-]/home/dba/test/file15.txt8.从安全的角度来看,您可能希望将“fdupes”的输出打印到一个文件中,然后检查该文本文件以确定要删除哪些文件。这减少了意外删除文件的机会。您可以这样做:$fdupes-Sr/home>/home/fdupes.txt注意:您可以将“/home”替换为您想要的文件夹。如果您想分别递归搜索和打印大小,也可以使用选项“-r”和“-S”。9.您可以使用选项-f省略每组匹配项中的第一个文件。首先列出目录的文件。[root@192_168_209_128test]#ls-l/home/dba/testtotal60-rw-r--r--1rootroot12Apr1023:22file10.txt-rw-r--r--1root根10年4月12日23:22file11.txt-rw-r--r--1rootroot10年4月12日23:22file12.txt-rw-r--r--1rootroot12Apr1023:22file13。txt-rw-r--r--1rootroot12Apr1023:22file14.txt-rw-r--r--1rootroot12Apr1023:22file15.txt-rw-r--r--1rootroot12Apr1023:22file1.txt-rw-r--r--1rootroot12Apr1023:22file2.txt-rw-r--r--1rootroot12Apr1023:22file3.txt-rw-r--r--1rootroot12Apr1023:22file4.txt-rw-r--r--1rootroot12Apr1023:22file5.txt-rw-r--r--1rootroot12Apr1023:22file6.txt-rw-r--r--1rootroot12Apr1023:22file7.txt-rw-r--r--1rootroot12Apr1023:22file8.txt-rw-r--r--1rootroot12Apr1023:22file9.txt然之后从每组匹配项中省略第一个文件。[root@192_168_209_128测试]#fdupes-f/home/dba/test/home/dba/test/file2.txt/home/dba/test/file3.txt/home/dba/test/file4.txt/home/dba/test/file5.txt/home/dba/test/file6.txt/home/dba/test/file7.txt/home/dba/test/file8.txt/home/dba/test/file9.txt/home/dba/test/file10.txt/home/dba/test/file11.txt/home/dba/test/file12.txt/home/dba/test/file13.txt/home/dba/test/file14.txt/home/dba/测试/文件15.txt10。检查安装的fdupes版本。[root@192_168_209_128测试]#fdupes-versionfdupes1.6.1
