Extracting Nested Zip Files – Methods and Tools

filesscriptingzip

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?

Best Answer

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.

while [ "`find . -type f -name '*.zip' | wc -l`" -gt 0 ]
do
    find . -type f -name "*.zip" -exec unzip -- '{}' \; -exec rm -- '{}' \;
done
Related Question