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

redsquash

macrumors member
Original poster
May 6, 2008
75
0
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
 

CarreraGuy

macrumors regular
Jan 15, 2013
148
0
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
If you are comfortable with Terminal.app 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.
 

redsquash

macrumors member
Original poster
May 6, 2008
75
0
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
 

CarreraGuy

macrumors regular
Jan 15, 2013
148
0
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?
 

ssls6

macrumors 6502a
Feb 7, 2013
558
153
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
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.
 

balamw

Moderator
Staff member
Aug 16, 2005
19,366
978
New England
Is there a quick and easy way to do this?
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.

B
 

Partron22

macrumors 68030
Apr 13, 2011
2,569
758
Yes
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:
mook copy 2.app
mook copy 3.app
mook copy 4.app
mook copy 5.app
mook copy 6.app
mook copy.app
mook.app
A little Applescript can clean them up for you.
Code:
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.
 

redsquash

macrumors member
Original poster
May 6, 2008
75
0
The files are not the same but would have tte word copy attached somewhere

mooke copy 2.app
vdmook copy 3.app
sevek copy 4.mp4
mtyuook copy 5.app
msecctyook copy 6.doc
mook copy.app
 

ScoobyMcDoo

macrumors 65816
Nov 26, 2007
1,188
35
Austin, TX
The files are not the same but would have tte word copy attached somewhere

mooke copy 2.app
vdmook copy 3.app
sevek copy 4.mp4
mtyuook copy 5.app
msecctyook copy 6.doc
mook copy.app
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.
 

calaverasgrande

macrumors 65816
Oct 18, 2010
1,291
161
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?
 

w0lf

macrumors 65816
Feb 16, 2013
1,233
75
USA
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?
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.
 

SlCKB0Y

macrumors 68040
Feb 25, 2012
3,140
205
Sydney, Australia
The files are not the same but would have tte word copy attached somewhere

mooke copy 2.app
vdmook copy 3.app
sevek copy 4.mp4
mtyuook copy 5.app
msecctyook copy 6.doc
mook copy.app
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.

Code:
find /Users/USERNAME/somedir -type f -name '* copy*' -exec mv {} ~/.Trash \;
* ENSURE YOU HAVE A WORKING BACKUP BEFORE PROCEEDING

* 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”.

----------

Best option would be to use a trash script rather than rm though.
I agree!

----------

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?
That would not delete their entire hard drive. On a stock system they would get permission denied without using su or sudo.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.