I was unzipping a boatload of zip files today, and I casually entered “unzip *zip” into my Linux command line.

No way, said my system.

Instead of unzipping the files, I got a bunch of warnings that read: “caution: filename not matched,” followed by a filename.  At the end of the listing, unzip told me “1 archive had fatal errors.”  (And that’s the clue… 1 archive.)

To understand what’s happening here, you have to understand what happens when you use a wildcard in a Unix shell.  When you type “unzip *zip,” your shell (bash, bourne, korn, whatever) doesn’t actually pass that “*” to the program you’re calling – instead, it performs the wildcard match against the specified files, then passes the list of files to the program. 

So when you type “unzip *” in a directory containing files A, B, C, and D, your shell actually calls the unzip program with 4 arguments – A, B, C, and D.  A quick check of the unzip man page shows that unzip accepts only one archive name, and treats subsequent file names as files you want to extract from that archive.  In other words, when you type “unzip *”, you’re really saying “unzip A B C D”, which unzip translates into “Oh, you want me to pull files B, C, and D out of archive A.”

To work around this problem, you need only escape the wildcard operator to prevent the shell from translating it. 

So instead of “unzip *zip” type “unzip \*zip”.