How can I delete copies of tens of thousands of files ?

Discussion in 'OS X Mavericks (10.9)' started by redsquash, Dec 11, 2013.

  1. redsquash macrumors member

    May 6, 2008
    I have 2, 3, 4 or more copies of some files which I want to delete.
    There are tens of thousands of copies of files to be deleted .

    Highlighting and deleting these 200 at a time will take forever,
    which is what I have started to do.

    I just want one file only to exist and not several. Is there a quick and easy way to do this?

    thanks in advance
  2. CarreraGuy macrumors regular


    Jan 15, 2013
    If you are comfortable with you can do:

    $ rm -f <some_file_name_pattern>.<extension>
    (the -f is force so you won't get confirmation for each one)

    You can also use it in combination with find and recurse directories:

    $ find . -name '*.bak' -exec rm -f {} \;

    Find is powerful because you can also search on dates - created, modified, accessed, etc...

    Basically you have a lot of options, but read up on Linux/Unix shell commands if you are not familiar.
  3. redsquash thread starter macrumors member

    May 6, 2008
    Hello Carraraguy,
    The files do not have a common name or extension.

    I have never used terminal.

    I was hoping for some sort of command that would remove files which had duplicate names
  4. CarreraGuy macrumors regular


    Jan 15, 2013
    Well if the filenames are identical they must be in a different directory. If you know the files are identical you can copy them to the folder you want them in. Then just delete the other folder?
  5. ssls6 macrumors 6502a


    Feb 7, 2013
    When I face this problem, I get a directory listing redirected to a file, manipulate the file into a script, then run the script. A block editor really helps when doing this.

    If you can give examples of file names you want to keep versus those you want to delete, you'll get better help.
  6. balamw Moderator


    Staff Member

    Aug 16, 2005
    New England
    Check out dupeGuru it can find the files and will select those duplicates you choose automatically so you can delete them permanently or send to Trash.

    There are plenty of other similar tools. I like this one because it has many options and has had an interesting business model.

  7. Partron22 macrumors 68020


    Apr 13, 2011
    If the files really have duplicate names, but are in different folders, just merge folders until there's only one copy of each file left.

    If the files are copies with names like:
    A little Applescript can clean them up for you.
    tell application "Finder"
    	set sourcefolder to (choose folder) as string -- (folder name must appear in popup at top of dialog)
    	set myfiles to every file of folder sourcefolder
    	set numfiles to count of myfiles
    	repeat with n from 1 to numfiles
    		if name of item n of myfiles contains "copy" then
    			move item n of myfiles to trash
    		end if
    	end repeat
    end tell
    The above will move every file whose name contains the word "copy" from a folder of your choosing to the trash.
  8. redsquash thread starter macrumors member

    May 6, 2008
    The files are not the same but would have tte word copy attached somewhere

    mooke copy
    vdmook copy
    sevek copy 4.mp4
    mtyuook copy
    msecctyook copy 6.doc
  9. ScoobyMcDoo macrumors 65816

    Nov 26, 2007
    Austin, TX
    Are all of the files in the same folder?

    If so, I would use terminal. I know you said you never used it, but that would be the easiest.

    Try this:

    Open terminal. Use the cd command to get to the folder you want to delete files from: E.G:

    cd Documents

    Now, type this command:

    ls *copy*

    This will produce a list of files that match that file spec. If all of the files listed are ones you want to delete, type the command:

    rm *copy*

    Just a fair warning - the rm command will delete the files - it will not move them to the trash. The only possibility of restoring these deleted files would be from a backup.
  10. calaverasgrande macrumors 65816


    Oct 18, 2010
    Brooklyn, New York.
    honestly, terminal my be second nature to some of us, but for newbies it is daunting and dangerous. Just using CD to navigate is a day long course in itself for most people. (cd .. to "go up" is a major revelation in these cases)
    If they are not accustomed to navigating directories from a command line, advising them to use RM for anything is almost pathological.
    Especially with -f.
    Hey why not just cd / and run rm -r -f and throw in a -v so you can see your entire hard drive deleted with verbosity?
  11. w0lf macrumors 65816


    Feb 16, 2013
    This is true. I once accidentally nuked half my harddrive using rsync with the delete before option.

    That being said terminal is still probably the best way to delete a bunch of files.

    Best option would be to use a trash script rather than rm though.
  12. SlCKB0Y macrumors 68040


    Feb 25, 2012
    Sydney, Australia
    The following command should be run in a terminal. It will recursively move all files under a given directory which contain " copy" anywhere in their name to your Trash, where they can be checked before deleting.

    find /Users/USERNAME/somedir -type f -name '* copy*' -exec mv {} ~/.Trash \;

    * Replace “/Users/USERNAME/somedir” with the highest level directory you want to search from

    * Files with identical names will be merged in the trash (only one copy retained)

    * Files to be moved must contain the word “copy” with a space before it. Eg. filename copy1.jpg

    * Before emptying your trash, check that no needed files were moved in error. Any that are can be right clicked on and “Put Back”.


    I agree!


    That would not delete their entire hard drive. On a stock system they would get permission denied without using su or sudo.
  13. calaverasgrande macrumors 65816


    Oct 18, 2010
    Brooklyn, New York.
    I deliberately left out the sudo bit.

Share This Page