PDA

View Full Version : Copying all files of a type to a folder


Luck
06-14-2004, 10:45 PM
Howdy.

I know there must be a way to do this, but I am unsure how.

iTunes has messed up my mp3 collection, duplicating many files. For example, in the library there are "Song", "Song 1", "Song 2", etc, that are all copies. I don't really know why this occured, but it has eaten up much of my free hard drive space.

Thus, I would like to take every .mp3 file on my Mac and put them in one folder. Then I would manually delete the dupes, giving me my normal collection back and freeing up space.

Trying to do the copy in the GUI is too much for my little G4 to handle, as with duplicates it's something like 4000 files.

My question: How would I move all the .mp3 files on all disks to one folder using Terminal? Probably mv something, but I really don't know Unix much.

Thanks for the help.

ulrichm
06-15-2004, 12:50 AM
What you can do is use the 'find' feature of the Finder and search for all mp3s on your computer.
Once found, you drag all the files you wish to a new folder. The Finder will then move your mp3s to this new folder.
I have also a G4 and it copes well with almost 1000 mp3s.

acme.mail.order
06-15-2004, 08:35 AM
For deleting the duplicates, a brief web search (http://elonen.iki.fi/code/misc-notes/remove-duplicate-files/) produced this nifty script:

#!/bin/bash
OUTF=rem-duplicates.sh
echo "#! /bin/sh" > $OUTF
find -type f | while read x
do md5sum "$x"
done | sort --key=1,32 | uniq -w 32 -d --all-repeated=separate | sed -e "s/^/#rm \"/g" -e 's/$/\"/g' >> $OUTF
chmod a+x $OUTF
ls -l $OUTF

I've edited it to remove the slightly buggy filename escapes and replace them with quotes. It does NOT keep one of the duplicates - you must edit the script output file manually to figure out which duplicates get deleted.

FiercePanda
06-19-2004, 03:06 PM
if you just want to move all your mp3s to a folder, you could try the following:

mkdir /mp3folder; find / -name '*.mp3' | xargs -i mv \{\} /mp3folder

(I should mention that I'm still on jaguar, and my xargs command doesn't have the -i option, I hope they've added it for panther...).

mervTormel
06-19-2004, 03:49 PM
if you just want to move all your mp3s to a folder, you could try the following:

mkdir /mp3folder; find / -name '*.mp3' | xargs -i mv \{\} /mp3folder


this could be destructive. for example, finding these results:

Art Blakey Quintet/A Night At Birdland/A Night In Tunisia.mp3
Lee Morgan/The Best Of Lee Morgan/A Night In Tunisia.mp3


the mv command would destroy Art Blakey's version.

FiercePanda
06-19-2004, 11:35 PM
this could be destructive. for example, finding these results:

Art Blakey Quintet/A Night At Birdland/A Night In Tunisia.mp3
Lee Morgan/The Best Of Lee Morgan/A Night In Tunisia.mp3


the mv command would destroy Art Blakey's version.

Good point. That didn't occur to me, as I have mv aliased to 'mv -i' for safety. I still can't think of an easy way to get all the duplicates renamed and moved into the same directory though.