How do I unzip multiple / many files under Linux?

by on March 4, 2007 · 19 comments· LAST UPDATED March 4, 2007

in , ,

Q. I’ve lots of files in a directory called /disk2/images. All files are zip file format , so I am using following command:

unzip *.zip

Which is result into an error as follows:

caution: filename not matched

How do I unzip multiple / many files under Linux?

A. Linux or UNIX unzip command will list, test, or extract files from a ZIP archive, commonly found on MS-DOS systems.

When you want to unzip file using wild card, you have two options as follows.

Option # 1 : unzip multiple files using single quote (short version)

Type the command as follows:
$ unzip ‘*.zip’

Note that *.zip word is put in between two single quote, so that shell will not recognize it as a wild card character.

Option # 2 : unzip multiple files using shell for loop (long version)

You can also use for loop as follows:
$ for z in *.zip; do unzip $z; done

See also

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 19 comments… read them below or add one }

1 Kamchybek Jusupov March 6, 2007 at 9:39 am

# If files are password protected, and we are not sure which password

for Z_FILE in *.zip; do
for PASSWD in [ pass123, PASS123, abc123, ABC123 ]; do
unzip -P $PASSWD $Z_FILE;
if [ $? = 0 ]; then # successful unzip
break
fi
done
done

Reply

2 nixCraft March 6, 2007 at 10:52 am

Kamchybek,

This is an excellent hack.

Appreciate your post.

Reply

3 Kamchybek Jusupov March 21, 2007 at 10:11 am

> Appreciate your post.

No probs, copyleft (c) :)

Actually I’ve seen yours:

$ for z in *.zip; do unzip $z; done

But, it was not enough for me, ’cause we have password protected ones… So, can say that idea comes from you :) I just added a new feature (validation)…

I think it should/can be improved further to check for other exit status codes…

Maybe later some day…

Reply

4 Bobby Cox April 8, 2007 at 2:54 am

I used to use for i in *.zip ; do unzip $i ; done as well but then I found out about the following command and use it all the time now.

unzip \*.zip

escape the asterik and you are good to go. :)

Reply

5 Naresh July 26, 2007 at 9:43 am

Hi

I tried unzip -P $PASSWD $Z_FILE; command but it is not working and for same zip file it is working in US with same password. I read in one of the web sites that, non USA system needs to install a patch for running above command. If yes Please let me know where can I get this patch else please let me know how to run this command.

Thanks
Naresh

Reply

6 Oberg January 24, 2009 at 4:05 pm

Thanks, just what I needed! Very straitghtforward. +1 virtual cookie for you.

Reply

7 some dude April 25, 2009 at 7:04 am

If you have spaces in your filenames, you can also use the following:

for z in *.zip; do unzip “$z”; done

Reply

8 Ragu May 11, 2009 at 8:52 pm

find -name \*.zip -exec unzip {} \;

find -name \*.zip | xargs -t -i unzip {}

Reply

9 moshe beeri May 31, 2009 at 12:08 pm

If you like to extract multiple tar or tar.gz use the following command
for f in *.tar.gz; do tar zxf $f; done

Reply

10 Kaithy Aravind Reddy December 27, 2009 at 4:30 am

Thanks all for sharing, very useful information about Unzip.

Reply

11 eladio matos February 18, 2010 at 6:01 pm

Question: and if I want do delete a file in a batch of different compressed archives? Lets say all copies of “info.txt” or “logo.jpg” in a.zip, b.zip, c.zip(…) z.zip, etc. There is a way to do it?

Reply

12 vipin kumar January 12, 2012 at 5:26 am

excellent post …. short method is really awesome..

Reply

13 Jane January 16, 2012 at 12:41 pm

Exactly what I was looking for! THANK YOU!

Reply

14 Paul February 21, 2012 at 12:10 pm

Time saver, life saver! Thank you!

Reply

15 pradeep chourasiya May 22, 2012 at 5:52 am

thanks a lot …..4 help

if u want to display some msg then…

for z in *.zip;
do unzip $z;
done
echo “ALL FILE ARE UNZIP SUCCESSFULLY”

Reply

16 Radina October 23, 2012 at 5:37 pm

Thanks everyone for the answers. If space is an issue, you can do something like (from some dude) to remove the archive files as they are unpackaged:
for z in *.zip; do unzip $z; rm $z; done

Reply

17 sarita November 3, 2013 at 4:54 am

I have 1..10 zip files in one directory …i want to unzip all files at a time..
can any one help how to do that

Reply

18 Tarun Nagpal January 26, 2014 at 12:39 pm

Thank you very much.

Reply

19 Tony September 13, 2014 at 6:07 pm

I used:

unzip “*.zip” -d ~/.fonts/

Reply

Leave a Comment

Tagged as:

Previous Faq:

Next Faq: