Fdupes описание
Fdupes – это программа для сканирования каталогов для дубликатов файлов.
Он распознает дубликаты, используя подпись MD5 файлов вместе с байтовым сопоставлением.
Параметры списка, замены и удаления могут использоваться вместе с fdupes.
Он запрограммирован на языке C и выпущен под лицензией MIT. Установка fdupes объясняется в этой статье
fdupes сравнивает файлы в следующем порядке:
Сравнение размеров -> Частичное сравнение подписи MD5 -> Полное сравнение подписи MD5 -> Сравнение байтов с байтами.
Установка fdupes в Linux
Выполните следующую команду для установки последней версии fdupes.
В системе Fedora и CentOS / RHEL
Включите репозиторий epel перед установкой пакета fdupes.
Затем запустите следующую команду для установки:
# yum install fdupes
Важно. В Fedora менеджер пакетов yum по умолчанию заменяется на «dnf».
В системах на базе Debian
# apt-get install fdupes -y Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libavahi-client-dev libavahi-common-dev libavahi-compat-libdnssd1 libdbus-1-dev libjs-jquery libruby2.1 libyaml-0-2 ruby2.1 rubygems-integration Use 'apt-get autoremove' to remove them. The following NEW packages will be installed: fdupes 0 upgraded, 1 newly installed, 0 to remove and 226 not upgraded. Need to get 16.8 kB of archives. After this operation, 69.6 kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com/ubuntu/ wily/main fdupes amd64 1.51-1 [16.8 kB] Fetched 16.8 kB in 0s (25.3 kB/s) Selecting previously unselected package fdupes. (Reading database ... 180830 files and directories currently installed.) Preparing to unpack .../fdupes_1.51-1_amd64.deb ... Unpacking fdupes (1.51-1) ... Processing triggers for man-db (2.7.4-1) ... Setting up fdupes (1.51-1) ...
Как использовать команду fdupes
Давайте создадим несколько повторяющихся файлов в разделе «/home/user1/ itsecforu».
# mkdir /home/user1/linuxhelp && cd /home/user1/linuxhelp && for i in {1..25}; do echo "Welcome to linuxhelp." > file${i}.txt ; done
Выполните следующую команду, чтобы убедиться, что файлы дубликатов созданы:
# ls -l total 100 -rw-r--r-- 1 root root 22 May 24 09:25 file1.txt -rw-r--r-- 1 root root 22 May 24 09:25 file2.txt -rw-r--r-- 1 root root 22 May 24 09:25 file3.txt -rw-r--r-- 1 root root 22 May 24 09:25 file4.txt -rw-r--r-- 1 root root 22 May 24 09:25 file5.txt -rw-r--r-- 1 root root 22 May 24 09:25 file6.txt -rw-r--r-- 1 root root 22 May 24 09:25 file7.txt -rw-r--r-- 1 root root 22 May 24 09:25 file8.txt -rw-r--r-- 1 root root 22 May 24 09:25 file9.txt -rw-r--r-- 1 root root 22 May 24 09:25 file10.txt -rw-r--r-- 1 root root 22 May 24 09:25 file11.txt -rw-r--r-- 1 root root 22 May 24 09:25 file12.txt -rw-r--r-- 1 root root 22 May 24 09:25 file13.txt -rw-r--r-- 1 root root 22 May 24 09:25 file14.txt -rw-r--r-- 1 root root 22 May 24 09:25 file15.txt -rw-r--r-- 1 root root 22 May 24 09:25 file16.txt -rw-r--r-- 1 root root 22 May 24 09:25 file17.txt -rw-r--r-- 1 root root 22 May 24 09:25 file18.txt -rw-r--r-- 1 root root 22 May 24 09:25 file19.txt -rw-r--r-- 1 root root 22 May 24 09:25 file20.txt -rw-r--r-- 1 root root 22 May 24 09:25 file21.txt -rw-r--r-- 1 root root 22 May 24 09:25 file22.txt -rw-r--r-- 1 root root 22 May 24 09:25 file23.txt -rw-r--r-- 1 root root 22 May 24 09:25 file24.txt -rw-r--r-- 1 root root 22 May 24 09:25 file25.txt
Поиск дубликатов файлов
Выполните следующую команду для поиска дубликатов файла:
# fdupes /home/user1/itsecforu /home/user1/itsecforu/file1.txt ... /home/user1/itsecforu/file25.txt
Используйте параметр -r для поиска рекурсивно повторяющихся файлов в каждом каталоге, включая его подкаталоги.
# fdupes -r /home/ /home/user1/.sudo_as_admin_successful /home/user1/.cache/sso/sso-client-gui.log /home/user1/.local/share/unity-settings-daemon/input-sources-converted /home/user1/.config/compiz-1/compizconfig/config /home/user1/.gconf/apps/%gconf.xml /home/user1/.local/share/.converted-launchers /home/user1/.config/unity/first_run.stamp /home/user1/.cache/motd.legal-displayed /home/user1/.local/share/zeitgeist/fts.index/flintlock /home/user1/itsecforu/file1.txt ... /home/user1/itsecforu/file25.txt
Чтобы просмотреть размер дубликатов, найденных в папке, используйте команду ниже:
# fdupes -S /home/user1/linuxhelp/ 22 bytes each: /home/user1/itsecforu/file1.txt ... /home/user1/itsecforu/file25.txt
Чтобы просмотреть размер повторяющихся файлов для каждого каталога и подкаталогов, встречающихся внутри, используйте параметр «-Sr» следующим образом:<
# fdupes -Sr /home/ 0 bytes each: /home/user1/.sudo_as_admin_successful /home/user1/.cache/sso/sso-client-gui.log /home/user1/.local/share/unity-settings-daemon/input-sources-converted /home/user1/.config/compiz-1/compizconfig/config /home/user1/.gconf/apps/%gconf.xml /home/user1/.local/share/.converted-launchers /home/user1/.config/unity/first_run.stamp /home/user1/.cache/motd.legal-displayed /home/user1/.local/share/zeitgeist/fts.index/flintlock 22 bytes each: /home/user1/itsecforu/file1.txt ... /home/user1/itsecforu/file25.txt
Как удалить дубликаты файлов
Используйте опцию ‘-d’ для удаления дубликатов файлов.
Все дубликаты перечислены, и теперь вы можете удалять, по одному, все или в определенном диапазоне.
За исключением одного файла, мы можем удалить все остальные файлы, выполнив следующую команду.
# fdupes -d /home/user1/itsecforu/
Здесь, за исключением файла file17.txt, все остальные файлы удаляются.
Для обеспечения безопасности вы также можете показать вывод «fdupes» в файл, а затем удалить, используя следующую команду:
# fdupes -Sr /home &gt; /home/fdupes.txt
Важно: вы можете заменить «/ home» на желаемую папку.
Также используйте опции «-r» и «-S», если вам нужно искать рекурсивно и размер печати.
Проверить версию
# fdupes --version fdupes 1.51
Если вы хотите узнать больше опций в fdupes, используйте параметр -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