Advertisement: Linux VPS from $4/month - contact support for custom offer.
+ Post New Thread
Results 1 to 1 of 1

Thread: fdupes delete command - how to execute deletion after selecting items

  1. #1
    Administrator
    Join Date
    Mar 2013
    Posts
    2,817

    fdupes delete command - how to execute deletion after selecting items

    When running fdupes on certain folder with -d (delete) parameter:

    -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
    and selecting some duplicates, then fdupes fails to conveniently suggest which command to run in order to execute deletion of the selected items.

    After spending time on help page ("h" key + enter) one can find:

    Once tagged for deletion, files can be deleted by pressing DELETE key or using the 'prune' command.
    So that is it the command to use.

    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:
    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
    DELETE THAT DUPLICATES:
    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')"
    (keep quotation marks not to accidentally delete wrong files)

    B) after skipping/omitting first duplicate, duplicates which ARE located in a path/folder/drive that contains certain string/name.:

    SHOW DUPLICATES TO DELETE:
    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
    (keep quotation marks not to accidentally delete wrong files)
    DELETE THAT DUPLICATES:
    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')"
    (keep quotation marks not to accidentally delete wrong files)

    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)"
    Last edited by Fli; 10-16-2024 at 01:28 PM.

+ Post New Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
 Protected by : ZB BLOCK  &  StopForumSpam