About Linux FAQ

Browse More FAQs:

How do I unzip multiple / many files under Linux?

Posted by Vivek Gite [Last updated: March 4, 2007]

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

E-mail this to a friend      Printable version

Related Other Helpful FAQs:

Discussion on This FAQ

  1. Kamchybek Jusupov Says:

    # 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

  2. nixcraft Says:

    Kamchybek,

    This is an excellent hack.

    Appreciate your post.

  3. Kamchybek Jusupov Says:

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

  4. Bobby Cox Says:

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

  5. Naresh Says:

    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

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.