2

I have thousands of .zip files in one folder, I want to extract those using command or script, each .zip file to it own folder. I wish to run the unzip process multiple times. How can i do that?

  • @Siraj this question is about multiple ZIP files at a time, not about ZIP files within ZIP files. – Chai T. Rex Feb 28 '17 at 0:57
1

This will do the trick, run this on terminal

for f in *.zip; do unzip $f -d ${f%.*}; done

Ok redefined answer taking into consideration the comment:

In one file named unzip.sh put this code:

#!/bin/bash
LEN=${#}
COUNT=0
PROCESSES=20
ITERATE=$(( LEN/PROCESSES ))
for ((i=0;i<=ITERATE;i++))
do 
    LOWER=$(( i*PROCESSES+1 ))
    HIGHER=$(( (i+1)*PROCESSES ))
    ./aux.sh ${@:$LOWER:$HIGHER} &!
done

In one file named aux.sh put this code:

#!/bin/bash
for f in $@; do unzip $f -d ${f%.*}; done

Remember to set both files with executions permissions by typing in the terminal: chmod +x unzip.sh aux.sh Now all you have to do is executing the script by typing in the terminal: ./unzip.sh *.zip

  • Thank you, but i wish to run the unzip process several times because there are thousands of .zip files. – yarone Feb 27 '17 at 17:51
  • You want to unzip some zips each time and running the script several times until you made it? If so, can the zips already unzipped be deleted? – Diogo Vilela Feb 27 '17 at 17:54
  • I want to extract zip files, in order to accomplish it in a short time i wish to run the unzip process itself several times (parallel), each zip to its own folder. – yarone Feb 27 '17 at 19:25
  • Ok i think I can do a little script for you to run if you're interest, I'll post as another answer – Diogo Vilela Feb 27 '17 at 22:14
  • Thank you @Diogo Vilela, will it extract each zip file in its own folder? – yarone Feb 28 '17 at 16:03
0

xargs with -P n can be used to run a program in parallel for multiple files. The following, for example, runs 8 instances of unzip in parallel.

cd directory-with-zip-files
find . -name '*.zip' -print0 | xargs -0 -n 1 -P 8 unzip
0

If the files inside the zip files are in their respective folders, an easier solution would be to type this in the opened terminal of the zip files' folder:

unzip "*.zip"

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.