How do you unzip a compressed file?

How to unzip my iTunes Library backup?

  • 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?

  • Answer:

    find music_dir -type f -name *.zip -execdir unzip -r {} \;

wheat at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

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) doneI 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.

Skorgu

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.

fogster

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.

philomathoholic

To nitpick my nitpick, I missed the part where you already knew about compressing compressed files. Sorry about that.

philomathoholic

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.

wheat

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.