Removing newer identical files in same directory?
I'd like to be able to scour a directory, removing all duplicated files except for the one with the oldest modification date.
I can't think of a method to do so? Is this a simple task for Linux or will it involve some scripting? The logic is basically this... 1. Find the oldest file. 2. Remove any other files in this directory that are identical. 3. Find the next oldest file. 4. Remove any other files in the directory that are identical. 5. Repeat steps 3 and 4 until all the duplicates are gone. ...and what if I only wanted the most recent modification date instead of the oldest? |
If the files are identical what difference does it make as to which one you save?
------------------------- Steve Stites |
Quote:
If it's an easy task to delete all the duplicates without regarding the timestamp, it should be a simple matter to sort the file list before trying to delete the duplicates... shouldn't it? |
You could use fdupes, I checked the source and it does actually sort by mtime. However, that feature is not documented so it's a little dicey to rely on it. For a one-off it should be okay to check the order is correct:
Code:
# if fdupes sort by mtime, blank lines should be only diff Code:
fdupes -d -N the-directory Code:
dupdir=$(mktemp -d --tmpdir dups-XXXXXX) |
All times are GMT -5. The time now is 10:07 AM. |