I have numerous zip archives, each of which contains a number of zip archives. What is the best way to recursively extract all files contained within this zip archive and its child zip archives, that aren't zip archives themselves?

@Gilles: Sorry, yeah it was a bit unclear. I changed it a bit, hopefully its more clear now.
– oadamsNov 28 '10 at 0:56

I was going to post an answer, but I believe it should go as a comment: Nested Archives increase the space you need! You probably mean the Zip file format, not just gzip. every zip file is already compressed, compressing them again, just creates more overhead, effectively increasing needed space.
– polemonNov 29 '10 at 3:44

Yeah, I didn't do it :P. Unfortunately I'm subjected to this bizarre way of distributing files.
– oadamsNov 29 '10 at 5:56

9 Answers
9

This will extract all the zip files into the current directory, excluding any zipfiles contained within them.

find . -type f -name '*.zip' -exec unzip -- '{}' -x '*.zip' \;

Although this extracts the contents to the current directory, not all files will end up strictly in this directory since the contents may include subdirectories.

If you actually wanted all the files strictly in the current directory, you can run

find . -type f -mindepth 2 -exec mv -- '{}' . \;

Note: this will clobber files if there are two with the same name in different directories.

If you want to recursively extract all the zip files and the zips contained within, the following extracts all the zip files in the current directory and all the zips contained within them to the current directory.

As far as I understand, you have zip archives that themselves contain zip archives, and you would like to unzip nested zips whenever one is extracted.

Here's a bash 4 script that unzips all zips in the current directory and its subdirectories recursively, removes each zip file after it has been unzipped, and keeps going as long as there are zip files. A zip file in a subdirectory is extracted relative to that subdirectory. Warning: untested, make a backup of the original files before trying it out or replace rm by moving the zip file outside the directory tree.

This perl script will extract each .zip file into its own subdirectory. Run the script more than once to handle nested zip files. It does not delete .zip files after extraction but you could make that change by adding an unlink() call.

@Thomas Themel: Are you sure that it doesn't recursively extract ZIP files? It can extract from deb files tar.gz recurisvely but i have no time atm to test it with nested zip archives :\
– user2648Dec 1 '10 at 22:58