When running fdupes on certain folder with -d (delete) parameter:
and selecting some duplicates, then fdupes fails to conveniently suggest which command to run in order to execute deletion of the selected items.-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
After spending time on help page ("h" key + enter) one can find:
So that is it the command to use.Once tagged for deletion, files can be deleted by pressing DELETE key or using the 'prune' command.
How to delete duplicates automatically, ones that are in certain folder?
There is a built-in way, but hard to guess the order in which the fdupes will be deleting (meaning which item will be preserved and which deleted).
There is a workaround if you know from which folder/drive you want duplicate files preserved or deleted.
Following commands will
- retain/preserve one of the duplicates no matter in which folder it is (I have not found any way to specify it in fdupes).
- delete rest of the duplicates if it is(or is not) located in certain folder or path
Per my understanding, this can only be beneficial to avoid deleting duplicates in certain directory (and its subdirectories).
A) after skipping/omitting first duplicate, only delete duplicates which ARE NOT located in a path/folder/drive that contains certain string/name.:
SHOW DUPLICATES TO DELETE:
DELETE THAT DUPLICATES:for path in "$(sudo fdupes --recurse --omitfirst '/path/where/to/search/duplicates/recursively/'|grep -v 'duplicates-with-this-in-path-will-be-deleted')"; do echo "$path"; done
(keep quotation marks not to accidentally delete wrong files)while read path; do gio trash "$path"; done <<< "$(sudo fdupes --recurse --omitfirst '/path/where/to/search/duplicates/recursively/'|grep -v 'duplicates-with-this-in-path-will-be-deleted')"
B) after skipping/omitting first duplicate, duplicates which ARE located in a path/folder/drive that contains certain string/name.:
SHOW DUPLICATES TO DELETE:
(keep quotation marks not to accidentally delete wrong files)for path in "$(sudo fdupes --recurse --omitfirst '/path/where/to/search/duplicates/recursively/'|grep 'duplicates-with-this-in-path-will-be-deleted')"; do echo "$path"; done
DELETE THAT DUPLICATES:
(keep quotation marks not to accidentally delete wrong files)while read path; do gio trash "$path"; done <<< "$(sudo fdupes --recurse --omitfirst '/path/where/to/search/duplicates/recursively/'|grep 'duplicates-with-this-in-path-will-be-deleted')"
fdupes can follow symbolic links by adding: --symlinks
------
Another option - delete all duplicates of the files of the folder A in folder B (in another words: among multiple folders/levels, delete duplicates only inside a defined folder and its subfolders)
1. deduplicate folder B:
show: sudo fdupes --recurse '/path/A/B'
delete: sudo fdupes --recurse '/path/A/B' -d
2. run command which will find duplicates and delete all which path contains the name of the folder B:
show: sudo fdupes --recurse '/path/A' '/path/B' '/path/C'|grep folder-B-or-path-unique-name
delete: while read path; do gio trash "$path"; done <<< "$(sudo fdupes --recurse '/path/A' '/path/B' '/path/C'|grep folder-B-or-path-unique-name)"
Bookmarks