fdupes - Nástroj příkazového řádku pro vyhledání a odstranění duplicitních souborů v Linuxu
Pro většinu uživatelů počítačů je běžným požadavkem najít a nahradit duplicitní soubory. Hledání a odstraňování duplicitních souborů je únavná práce, která vyžaduje čas a trpělivost. Nalezení duplicitních souborů může být velmi snadné, pokud váš počítač používá GNU/Linux, díky nástroji „fdupes“.
Co je fdupes?
Fdupes je linuxový nástroj napsaný Adrianem Lopezem v programovacím jazyce C vydaný pod licencí MIT. Aplikace je schopna najít duplicitní soubory v dané sadě adresářů a podadresářů. Fdupes rozpoznává duplikáty porovnáním podpisu MD5 souborů a následným porovnáním bajtů po bajtech. Pomocí Fdupes lze předat mnoho možností, jak vypsat, odstranit a nahradit soubory pevnými odkazy na duplikáty.
Srovnání začíná v pořadí:
Porovnání velikosti > Částečné porovnání podpisu MD5 > Úplné porovnání podpisu MD5 > Porovnání bajtů po bajtech.
Nainstalujte fdupes na Linux
Instalace nejnovější verze fdupes (fdupes verze 1.51) je stejně snadná jako spuštění následujícího příkazu na systémech založených na Debian, jako jsou Ubuntu a Linux Mint.
sudo apt-get install fdupes
Na systémech založených na CentOS/RHEL a Fedoře musíte pro instalaci balíčku fdupes zapnout úložiště epel.
yum install fdupes
dnf install fdupes [On Fedora 22 onwards]
Poznámka: Výchozí správce balíčků yum je nahrazen dnf z Fedory 22 dále…
Jak používat příkaz fdupes?
1. Pro účely demonstrace vytvořte několik duplicitních souborů v adresáři (řekněme tecmint) jednoduše jako:
mkdir /home/"$USER"/Desktop/tecmint && cd /home/"$USER"/Desktop/tecmint && for i in {1..15}; do echo "I Love Tecmint. Tecmint is a very nice community of Linux Users." > tecmint${i}.txt ; done
Po spuštění výše uvedeného příkazu ověřte, zda jsou duplicitní soubory vytvořeny nebo nejsou pomocí příkazu ls.
$ ls -l
total 60
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint10.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint11.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint12.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint13.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint14.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint15.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint1.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint2.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint3.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint4.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint5.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint6.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint7.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint8.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9.txt
Výše uvedený skript vytvoří 15 souborů, konkrétně tecmint1.txt, tecmint2.txt…tecmint15.txt a všechny soubory obsahují stejná data, tj.
"I Love Tecmint. Tecmint is a very nice community of Linux Users."
2. Nyní vyhledejte duplicitní soubory ve složce tecmint.
$ fdupes /home/$USER/Desktop/tecmint
/home/tecmint/Desktop/tecmint/tecmint13.txt
/home/tecmint/Desktop/tecmint/tecmint8.txt
/home/tecmint/Desktop/tecmint/tecmint11.txt
/home/tecmint/Desktop/tecmint/tecmint3.txt
/home/tecmint/Desktop/tecmint/tecmint4.txt
/home/tecmint/Desktop/tecmint/tecmint6.txt
/home/tecmint/Desktop/tecmint/tecmint7.txt
/home/tecmint/Desktop/tecmint/tecmint9.txt
/home/tecmint/Desktop/tecmint/tecmint10.txt
/home/tecmint/Desktop/tecmint/tecmint2.txt
/home/tecmint/Desktop/tecmint/tecmint5.txt
/home/tecmint/Desktop/tecmint/tecmint14.txt
/home/tecmint/Desktop/tecmint/tecmint1.txt
/home/tecmint/Desktop/tecmint/tecmint15.txt
/home/tecmint/Desktop/tecmint/tecmint12.txt
3. Vyhledejte duplikáty rekurzivně v každém adresáři včetně jeho podadresářů pomocí možnosti -r.
Prohledává všechny soubory a složky rekurzivně, v závislosti na počtu souborů a složek bude skenování duplikátů nějakou dobu trvat. Mezitím se vám zobrazí celkový pokrok v terminálu, něco takového.
$ fdupes -r /home
Progress [37780/54747] 69%
4. Zobrazte velikost duplikátů nalezených ve složce pomocí možnosti -S.
$ fdupes -S /home/$USER/Desktop/tecmint
65 bytes each:
/home/tecmint/Desktop/tecmint/tecmint13.txt
/home/tecmint/Desktop/tecmint/tecmint8.txt
/home/tecmint/Desktop/tecmint/tecmint11.txt
/home/tecmint/Desktop/tecmint/tecmint3.txt
/home/tecmint/Desktop/tecmint/tecmint4.txt
/home/tecmint/Desktop/tecmint/tecmint6.txt
/home/tecmint/Desktop/tecmint/tecmint7.txt
/home/tecmint/Desktop/tecmint/tecmint9.txt
/home/tecmint/Desktop/tecmint/tecmint10.txt
/home/tecmint/Desktop/tecmint/tecmint2.txt
/home/tecmint/Desktop/tecmint/tecmint5.txt
/home/tecmint/Desktop/tecmint/tecmint14.txt
/home/tecmint/Desktop/tecmint/tecmint1.txt
/home/tecmint/Desktop/tecmint/tecmint15.txt
/home/tecmint/Desktop/tecmint/tecmint12.txt
5. Pomocí voleb -S a -r můžete současně zobrazit velikost duplicitních souborů pro každý adresář a podadresář, se kterým se setkáte. , tak jako:
$ fdupes -Sr /home/avi/Desktop/
65 bytes each:
/home/tecmint/Desktop/tecmint/tecmint13.txt
/home/tecmint/Desktop/tecmint/tecmint8.txt
/home/tecmint/Desktop/tecmint/tecmint11.txt
/home/tecmint/Desktop/tecmint/tecmint3.txt
/home/tecmint/Desktop/tecmint/tecmint4.txt
/home/tecmint/Desktop/tecmint/tecmint6.txt
/home/tecmint/Desktop/tecmint/tecmint7.txt
/home/tecmint/Desktop/tecmint/tecmint9.txt
/home/tecmint/Desktop/tecmint/tecmint10.txt
/home/tecmint/Desktop/tecmint/tecmint2.txt
/home/tecmint/Desktop/tecmint/tecmint5.txt
/home/tecmint/Desktop/tecmint/tecmint14.txt
/home/tecmint/Desktop/tecmint/tecmint1.txt
/home/tecmint/Desktop/tecmint/tecmint15.txt
/home/tecmint/Desktop/tecmint/tecmint12.txt
107 bytes each:
/home/tecmint/Desktop/resume_files/r-csc.html
/home/tecmint/Desktop/resume_files/fc.html
6. Kromě rekurzivního vyhledávání v jedné složce nebo ve všech složkách si můžete vybrat podle potřeby ve dvou nebo třech složkách. Nemluvě o tom, že v případě potřeby můžete použít volbu -S a/nebo -r.
fdupes /home/avi/Desktop/ /home/avi/Templates/
7. Chcete-li duplicitní soubory smazat při zachování kopie, můžete použít možnost ‘-d‘. Při použití této možnosti je třeba věnovat zvýšenou pozornost, jinak byste mohli skončit ztrátou potřebných souborů/dat a myslet si, že proces je neobnovitelný.
$ fdupes -d /home/$USER/Desktop/tecmint
[1] /home/tecmint/Desktop/tecmint/tecmint13.txt
[2] /home/tecmint/Desktop/tecmint/tecmint8.txt
[3] /home/tecmint/Desktop/tecmint/tecmint11.txt
[4] /home/tecmint/Desktop/tecmint/tecmint3.txt
[5] /home/tecmint/Desktop/tecmint/tecmint4.txt
[6] /home/tecmint/Desktop/tecmint/tecmint6.txt
[7] /home/tecmint/Desktop/tecmint/tecmint7.txt
[8] /home/tecmint/Desktop/tecmint/tecmint9.txt
[9] /home/tecmint/Desktop/tecmint/tecmint10.txt
[10] /home/tecmint/Desktop/tecmint/tecmint2.txt
[11] /home/tecmint/Desktop/tecmint/tecmint5.txt
[12] /home/tecmint/Desktop/tecmint/tecmint14.txt
[13] /home/tecmint/Desktop/tecmint/tecmint1.txt
[14] /home/tecmint/Desktop/tecmint/tecmint15.txt
[15] /home/tecmint/Desktop/tecmint/tecmint12.txt
Set 1 of 1, preserve files [1 - 15, all]:
Můžete si všimnout, že jsou uvedeny všechny duplikáty a budete vyzváni k odstranění, buď jeden po druhém, nebo určitý rozsah, nebo všechny najednou. Můžete vybrat rozsah něco jako níže a odstranit soubory souborů určitého rozsahu.
Set 1 of 1, preserve files [1 - 15, all]: 2-15
[-] /home/tecmint/Desktop/tecmint/tecmint13.txt
[+] /home/tecmint/Desktop/tecmint/tecmint8.txt
[-] /home/tecmint/Desktop/tecmint/tecmint11.txt
[-] /home/tecmint/Desktop/tecmint/tecmint3.txt
[-] /home/tecmint/Desktop/tecmint/tecmint4.txt
[-] /home/tecmint/Desktop/tecmint/tecmint6.txt
[-] /home/tecmint/Desktop/tecmint/tecmint7.txt
[-] /home/tecmint/Desktop/tecmint/tecmint9.txt
[-] /home/tecmint/Desktop/tecmint/tecmint10.txt
[-] /home/tecmint/Desktop/tecmint/tecmint2.txt
[-] /home/tecmint/Desktop/tecmint/tecmint5.txt
[-] /home/tecmint/Desktop/tecmint/tecmint14.txt
[-] /home/tecmint/Desktop/tecmint/tecmint1.txt
[-] /home/tecmint/Desktop/tecmint/tecmint15.txt
[-] /home/tecmint/Desktop/tecmint/tecmint12.txt
8. Z bezpečnostního hlediska můžete chtít vytisknout výstup ‘fdupes‘ do souboru a poté zkontrolovat textový soubor, abyste se rozhodli, který soubor odstranit. Sníží se tak šance na náhodné smazání souboru. Můžete:
fdupes -Sr /home > /home/fdupes.txt
Poznámka: ‘/home’ můžete nahradit požadovanou složkou. Pokud chcete vyhledávat rekurzivně a velikost tisku, použijte také možnost ‘-r‘ a ‘-S‘.
9. První soubor z každé sady shod můžete vynechat pomocí možnosti ‘-f‘.
První seznam souborů v adresáři.
$ ls -l /home/$USER/Desktop/tecmint
total 20
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (3rd copy).txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (4th copy).txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (another copy).txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (copy).txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9.txt
a pak vynechat první soubor z každé sady shod.
$ fdupes -f /home/$USER/Desktop/tecmint
/home/tecmint/Desktop/tecmint9 (copy).txt
/home/tecmint/Desktop/tecmint9 (3rd copy).txt
/home/tecmint/Desktop/tecmint9 (another copy).txt
/home/tecmint/Desktop/tecmint9 (4th copy).txt
10. Zkontrolujte nainstalovanou verzi fdupes.
$ fdupes --version
fdupes 1.51
11. Pokud potřebujete pomoc s fdupes, můžete použít přepínač ‘-h‘.
$ fdupes -h
Usage: fdupes [options] DIRECTORY...
-r --recurse for every directory given follow subdirectories
encountered within
-R --recurse: for each directory given after this option follow
subdirectories encountered within (note the ':' at
the end of the option, manpage for more details)
-s --symlinks follow symlinks
-H --hardlinks normally, when two or more files point to the same
disk area they are treated as non-duplicates; this
option will change this behavior
-n --noempty exclude zero-length files from consideration
-A --nohidden exclude hidden files from consideration
-f --omitfirst omit the first file in each set of matches
-1 --sameline list each set of matches on a single line
-S --size show size of duplicate files
-m --summarize summarize dupe information
-q --quiet hide progress indicator
-d --delete prompt user for files to preserve and delete all
others; important: under particular circumstances,
data may be lost when using this option together
with -s or --symlinks, or when specifying a
particular directory more than once; refer to the
fdupes documentation for additional information
-N --noprompt together with --delete, preserve the first file in
each set of duplicates and delete the rest without
prompting the user
-v --version display fdupes version
-h --help display this help message
To je teď pro všechny. Dejte mi vědět, jak jste dosud nacházeli a odstraňovali duplicitní soubory v Linuxu? a také mi řekněte svůj názor na tento nástroj. Vložte svou cennou zpětnou vazbu do sekce komentářů níže a nezapomeňte nás lajkovat/sdílet a pomozte nám se šířit.
Pracuji na dalším nástroji nazvaném fslint k odstranění duplicitních souborů, který brzy zveřejním a vy si ho budete rádi číst.