My music Library has grown over the years but just like a person in dire need of a haircut, my music library is in dire need of file organization. I am writing this post because I believe there are others out there who are like me. We don’t want to lose the songs we paid for (nor the one’s we may have not paid for ;).
Note: I am using Windows 7 and Cygwin for this tutorial. If you have a mac, the commands I use should all work in the Mac Terminal. (Cygwin was just invented so Windows users could play in the Unix playground too!)
If you are like me, you probably are terrified of deleting a file or folder because you don’t want to loose anything. The side product of this behavior is music chaos.
Over time we have updated iTunes (and had problems every time). We have tried to delete duplicate files using iTunes’ lame duplicate file option only to find that deleting thousands of songs a major pain in the you-know-where.
Maybe some of you paid for an app to clean your music folders up but I’m going to take a shot in the dark here and say that didn’t work out too well for you, did it?
So I have been brushing up on Unix and browsing around to try and find ways to give my music library a sexy haircut.
First things first, I want have two folders.
One folder is from an old hard drive and I want to see if I have any songs inside that old folder that I don’t have inside my main music library folder. I’m going to geek out here and start calling folders ‘directories’ from now on. Here is a Unix script find the differences between the two directories. (I’m not a Unix expert so if you know a better way, please share).
diff -r “/cygdrive/e/Maxtor backup/PHIL-PC/C/Users/phil/Music/Amazon MP3” “/cygdrive/e/music/Music” > diff.txt
What does the above mean?
- diff is the command to find differences
- -r is recursive so it will check contents of files and folders inside of folders
- /cygdrive/e/Maxtor backup/PHIL-PC/C/Users/phil/Music/Amazon MP3 – is my old directory of music (note: be sure to surround directory with quotes)
- /cygdrive/e/music/Music – is my new directory of music (note: be sure to surround directory with quotes)
- > diff.txt – this will output the differences inside a text file named diff.txt (inside the current directory you are in)
To see the new file, type the following in your Cygwin command line:
To open the file type the following in your Cygwin command line:
Now we want to only find the differences in the first directory. When I opened the diff.txt file I found that if I searched for the string ‘Only in /cygdrive/e/Maxtor backup/PHIL-PC/C/Users/phil/Music/‘, I would only output the differences in my old music directory. We use the ‘grep‘ command in unix to search for stuff. I output what grep finds to a new file called new-diff-files.txt.
grep ‘Only in /cygdrive/e/Maxtor backup/PHIL-PC/C/Users/phil/Music/’ diff.txt > new-diff-files.txt
I then open open my new file in a nice editor like Sublime Text 2 (it’s great and I have a bunch of tutorials and screencasts on this site about it.. just search for Sublime Text 2) and begin looking at each old file I don’t have and begin one-by-one importing them into iTunes. While it’s not the best solution to this problem, it’s easy enough for me to follow and give my music library the haircut it desperately needs. I hope my sideburns are even.