How to unzip my iTunes Library backup?
August 17, 2008 10:43 AM   Subscribe

OS X filter: How can I recursively unzip files (in directories that are not zipped)?

One of my hard drives died, and took my iTunes Library with it (thanks, LaCie). Luckily, I have a backup (made with SyncBack while I was still on WinXP). I had zip-compression enabled in my backups, on a file-by-file basis. So what I'm left with is an iTunes library of uncompressed folders that contains individual mp3 files that are compressed (.zip, not .gzip). And, yeah, I know, compressing files that are already compressed is stupid, but it seemed like a good idea at the time.

I'm on OS X now, and I want to uncompress all of these and then drop them into iTunes. "gunzip -r *" doesn't work because they're in .zip (rather than .gzip). "unzip -r *" doesn't work because the directories are not also zipped.

Can anyone help me with a little shell script magic to traverse these directories and unzip everything? Or is there some other unzip utility out there that can handle this easily?
posted by wheat to Computers & Internet (6 answers total) 1 user marked this as a favorite
 
find music_dir -type f -name *.zip -execdir unzip -r {} \;
posted by philomathoholic at 11:02 AM on August 17, 2008 [1 favorite]


Something like:
for n in find -name "*.zip"; do echo unzip $n; done
will probably work, this will probably drop the uncompressed files into your current working directory (not where the .zip is). If you want them in-place you'd have to add something like
for n in find -name "*.zip"; do (cd `basename $n`; pwd; echo unzip $n) done
I haven't tested these, but I've used similar formulas in the past. They'll print the commands they would execute, remove the 'echo' if that looks right.
posted by Skorgu at 11:04 AM on August 17, 2008


Yup, Skorgu's advice is what I've used in the past. (And philomathoholic's looks good, too, just with different syntax.)

A brief explanation, though man for will tell you more than you ever want to know... The 'for' will loop over the results of find -name "*.zip", setting n (which you access as $n) equal to the name of one file on each iteration, and for that, it will "do" echo unzip $n: the $n is expanded to the filename, recall. (The "echo," as Skorgu explains, means that it'll just print the command it would run, so that you can verify it's doing what you want and then remove the 'echo'.)

One bit of advice, though: in theory, you could be super-slick and make the script run something like unzip $n && rm $n to unzip the .zip file and then delete it. And it sounds like it's great advice. But don't do that. Our old pal Murphy intervenes, at least whenever I try doing something like this. Something, somewhere, will go wrong, and the unzip won't work right. And you'll have to run the command again. But you can't, because you have no more zip files, because you deleted them all "to be slick" and do it all in one fell swoop.
posted by fogster at 12:24 PM on August 17, 2008


To be nitpicky (in case of .zip files in the current dir) you should quote my *.zip, and skorgu's $n's and basenames (in case of spaces in the name). When I do a basename call with an unknown name, I use "$(basename -- "$n")" (note the double quoting used, both inside and outside).

A bit of backup-related advice. What format are your songs in? aac? mp3? If they aren't in aiff or another uncompressed form (wav), then the zip compression doesn't really do much for the size of the file. Plus, it's possible to get a file that's larger when "compressed", versus uncompressed.
posted by philomathoholic at 1:15 PM on August 17, 2008


To nitpick my nitpick, I missed the part where you already knew about compressing compressed files. Sorry about that.
posted by philomathoholic at 1:18 PM on August 17, 2008


Response by poster: Thanks to everyone for the great advice, especially to fogster for walking through the code examples so I can understand them. I'll try one of these methods out and report back.

philomathoholic: yeah, they're almost all in .mp3 with some .aac. I was just lazy with my SyncBack setup. Zipping my other files saved a lot of space on my backup drive, but I needed to exclude this directory. I'm pretty sure there is a way to do that, but I didn't investigate it. So, lesson learned there. I have Time Machine rolling now, so this shouldn't be an issue in the future.
posted by wheat at 7:28 AM on August 18, 2008


« Older i got $10 burnin a hole...   |   Animals on the Ark? Newer »
This thread is closed to new comments.