How do I unzip multiple / many files under Linux?

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:

Above error indicate that you used the unzip command wrongly. It means extract invoices.zip, pictures.zip, and visit.zip files from inside the data.zip archive. Your shell expands the command ‘unzip *.zip’ it as follows:unzip data.zip invoices.zip pictures.zip visit.zip 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:

# 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

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.

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;

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() { dir='.'; [[ ! -z "${1// }" ]] && dir=$1; for z in *.zip; do q=$(echo $z | cut -f 1 -d '.'); unzip $z -d $dir/$q; done; }

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

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

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 http://uploadcoins.com , so for me worked # unzip \*.zip , all that 400K went ok :) , so again, You can use unzip \*.zip , Good luck