Extracting nested zip files

I have countless zip archives, each of which has a variety of zip archives. What is the most effective means to recursively extract all files had within this zip archive and also its youngster zip archives, that aren't zip archives themselves?

2019-05-13 05:50:08
Source Share
Answers: 5

You'll intend to take care instantly unzipping zip files within zip files:


It is feasible to devise a zip documents that generates a zip documents as result, which generates a zip documents as result, etc etc etc That is, you can make a zip documents that is a set oint of "unzip" the program.

Additionally, I appear to remember individuals making zip files that would certainly "take off", that is a really tiny zip documents would certainly unzip to multi - gigabytes of result. This is an element of the method of compression.

2019-05-18 04:32:19

unzip does not do this, due to the fact that the UNIX means is to do one point and also do that well, not take care of all insane grandfather clauses in every device. Hence, you require to make use of the covering (which gets the job done of "linking points with each other" well). This makes it a shows inquiry, and also given that ALL feasible shows inquiries have actually been addressed on StackOverflow, below: How do you recursively unzip archives in a directory and its subdirectories from the Unix command-line?

2019-05-17 20:05:16

As much as I recognize, you have zip archives that themselves have zip archives, and also you would love to unzip nested zips whenever one is removed.

Below is a bash 4 manuscript that unzips all zips in the existing directory and also its subdirectories recursively, gets rid of each zip documents after it has actually been unzipped, and also maintains going as long as there are zip files. A zip documents in a subdirectory is removed about that subdirectory. Caution : untried, make a back-up of the initial files prior to attempting it out or change rm by relocating the zip documents outside the directory tree .

shopt -s globstar nullglob
while set -- **/*.zip; [ $# -ge 1 ] do
  for z; do
    ( cd -- "$(dirname "$z")" &&
      z=${z##*/} &&
      unzip -- "$z" &&
      rm -- "$z"

The manuscript will certainly additionally operate in zsh if you change the shopt line with setopt nullglob.

Below is a mobile matching. The discontinuation problem is a little difficult due to the fact that find does not automatically return a standing to show whether it has actually located any kind of files. Caution : as above.

while [ -n "$(find . -type f -name '*.zip' -exec sh -c '
    cd "${z%/*}" &&
    z=${z##*/} &&
    unzip -- "$z" 1>&2 &&
    rm -- "$z" &&
    echo 1
')" ]; do :; done
2019-05-17 20:04:24

This will certainly extract all the zip files right into the existing directory site, leaving out any kind of zipfiles had within them.

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

Although this removes the materials to the existing directory site, not all files will certainly wind up purely in this directory site given that the materials might include subdirectories.

If you in fact desired all the files purely in the existing directory site, you can run

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

Note : this will certainly belt files if there are 2 with the very same name in various directory sites.

If you intend to recursively extract all the zip files and also the zips had within, the list below removes all the zip files in the existing directory site and also all the zips had within them to the existing directory site.

while [ "`find . -type f -name '*.zip' | wc -l`" -gt 0 ]; do find -type f -name "*.zip" -exec unzip -- '{}' \; -exec rm -- '{}' \;; done
2019-05-17 20:03:09

The most convenient means is to make use of atool : http://www.nongnu.org/atool/. It is a great manuscript that make use of zip, unzip, tar, rar etc programs to extract any kind of archive.

Usage atool -x package_name.zip to unzip them all or if you intend to utilize it in directory with several zip files make use of straightforward for loop:

for f in *; do atool -x $f; fi (you will certainly need to cd right into wanted directory with zip files prior to you utilize this).

2019-05-17 19:29:06