ubuntu - Removing files and directories that already exist in other directories

07
2014-07
  • user2949465

    I need a help writing a script. So basically I have directories named by current date, like 01-06-2014 02-06-2014 and so on each of these directories has files and subdirectories inside. But sometimes there are duplicates. Like 01-06-2014 and 02-06-2014 may both have directory named d01 or file named f001.jpg, and so on

    What I want to do is get rid of these same files and subdirectories, so that I don't use too much space (and besides, what's the point in having duplicates)

    What is the easiest way to do it? Can someone help? please!

  • Answers
  • Arkadiusz Drabczyk

    For finding and removing duplicated files in specified directories consider using fdupes. There is no point in rolling your own script unless you want to learn something.


  • Related Question

    linux - Remove duplicate files across separate directory trees
  • P-Nuts

    I have two directories: old/ and new/. Some of the files in old/ are duplicates of those in new/. Some merely have the same name, and a few may even have identical content but different names. I'm not interested in the subdirectory path to the files, so only an unqualified filename needs to be considered in the matching.

    I want to remove the duplicate files from old/, so that it only contains files not also found in new/. For cases where the filenames match, but not the contents, or vice-versa, I want to have this listed in some log.

    Has anyone encountered a similar problem, or have a better solution than hacking together a (perl or similar) script from scratch? A runtime dominated by calling md5sum on each file is acceptable.


  • Related Answers
  • 8088

    Of course! Check out FSlint:

    FSlint is a utility to find and clean various forms of lint on a filesystem. I.E. unwanted or problematic cruft in your files or file names. For example, one form of lint it finds is duplicate files. It has both GUI and command line modes.

    alt text

    FSlint is free and open source software.

  • Cristian Ciupitu

    fdupes - finds duplicate files in a given set of directories

    fdupes new/ old/
    

    -d for delete

    -N for don't ask

    fdupes -N -d new/ old/