How do I unzip multiple / many files under Linux?

last updated in Categories , , , ,

I have lots of files in a directory called /disk2/images/. All files are in zip file format, so I am using the following command to extract zip files:
     unzip *.zip
The command result into an error which read as follows:
     caution: filename not matched
How do I unzip multiple or many zip files under a Linux/Unix-like system?

Linux or Unix-like system use the unzip command to list, test, or extract files from a ZIP archive, commonly found on MS-DOS systems.


The problem with multiple zip files on Linux

Assuming that you have four file in a /disk2/images/ directory as follows:


Let us verify it with the ls command:
$ ls
Sample outputs:

To unzip all files, enter:
$ unzip *.zip
Sample outputs:

caution: filename not matched:
caution: filename not matched:
caution: filename not matched:

Above error indicate that you used the unzip command wrongly. It means extract,, and files from inside the archive. Your shell expands the command ‘unzip *.zip’ it as follows:
The solution is pretty simple when you want to unzip the file using the wild card; you have two options as follows.

#1: Unzip Multiple Files Using Single Quote (short version)

The syntax is as follows to unzip multiple files from Linux command line:

unzip '*.zip'

Type the following command as follows:
$ cd /disk2/images/
$ unzip '*.zip'
$ ls -l

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

#2: Unzip Multiple Files from Linux Command Line Using Shell For Loop (Long Version)

You can also use for loop as follows:

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


28 comment

  1. # 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

  2. > 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…

  3. 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. :)

  4. 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.


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

  6. 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,,…), etc. There is a way to do it?

  7. thanks a lot …..4 help

    if u want to display some msg then…

    for z in *.zip;
    do unzip $z;
  8. 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

  9. I had a pile of zip that each contained a index.html file and the archive structure had no folder.. They obviously had to be extracted in separate folders so as to not overwrite the so precious files. Since it was a temporary “view and delete” kind of thing and with well over a hundred files (not needing to be unzipped in a specific folder, current folder was just fine), i came up with this;

    for z in *.zip; do q=$(echo $z | cut -f 1 -d '.'); unzip $z -d ./$q; done;

    It basically extracts all the zip files to the current directory, into a folder named after the zip filename. Greatly inspired (if not totally ripped from!) NixCraft and

    Couple seconds after i figured “oh well”, i saved that much time so i might as well make something out of it… So instead of just ‘hardcoding’ it into a simple bash alias that doesn’t take parameters, I took a couple more minutes to have it let me at least input a base directory for extraction. Here’s what i came up with (function in .bashrc file);

    unzipALL() {
    [[ ! -z "${1// }" ]] && dir=$1;
    for z in *.zip; do
    q=$(echo $z | cut -f 1 -d '.');
    unzip $z -d $dir/$q;

    From the command line just use unzipAll to unzip to the current folder or pass it a folder name: unzipAll /tmp extracts all to /tmp/%filename%.

    It does perform a single basic check on the passed parameter but nothing too fancy (strip spaces before/after then checks against null). One could spend more time and cutomize it further, adding bad directory check and all that…

    I figure i’d share… thanks and hopefuly it can be of use to someone!

    I hope i didn’t break any rules posting a url in here, sorry if so heeh

    1. unzip *.zip does not work in bash.

      blah@blahblah:~/tmp-zip$ unzip *.zip
      caution: filename not matched:

      unzip \*.zip DOES work, still doesn’t solve the problem i faced of multiple same-name files…

      blah@blahblah:~/tmp-zip$ unzip \*.zip
      inflating: index.html
      inflating: portfolio.html
      inflating: services.html
      replace index.html? [y]es, [n]o, [A]ll, [N]one, [r]ename:

      unzip “*.zip” results in the same, btw.

      Hence the quick function. If you have a better way please share
      Also, while testing you assumptions, i found out that unzip tries to look for .ZIP files on it’s own – pretty neat… unzip \* would work (still not help with the issue…)

  10. I just pulled a lot of files (over 400K) all of them were in zip, i’m trying to make huge archive off free documents at , so for me worked # unzip \*.zip , all that 400K went ok :) , so again, You can use unzip \*.zip , Good luck

  11. I want a script to extract a particular file from the multiple zip folder.


  12. What should be the command to unzip all the files with a single command if the extension is .gz?

    I used the above unzip ‘*.gz’.But it doesn’t work.

    Archive: zid_ia_rcvbl_acct_eecucl.skp.gz
    End-of-central-directory signature not found. Either this file is not
    a zipfile, or it constitutes one disk of a multi-part archive. In the
    latter case the central directory and zipfile comment will be found on
    the last disk(s) of this archive.

    168 files had no zipfile directory.
    No zipfiles found.

Leave a Comment