Friday, February 18, 2011

Linux / Mac OS X cleaning music library

If you love to listen to music, you'll probably have a huge MP3 library. Imagine that you gathered a lot of MP3 and you never bothered to keep the library clean until it was too late, and now you've a massive amount of folders and mp3 files all together with trash ( .txt, .url, .nfo, etc etc ... ) and you decided it was the time to clean it up.

You could do it the hard way, using OS X "Spotlight", finding and removing the stuff you don't want or you can do it the smart way with the beauty of command line shell.

Here's a simple and very useful command that will remove all unwanted files keeping only the ones you want. Just fire up the command shell to the folder which is the base of your library and run the following command:


find . ! \( -iname '*.mp3' -o -iname '*.wma' -o -iname '*.m4a' -o -iname '*.cue' -o -iname '*.wav' \) -type f -exec rm {} \;

You can add another set of file extensions to ignore by appending -o -iname '*.newExtension' inside the parentheses.

No comments: