Thursday, October 4, 2012

Re-use, don't re-invent - How do I unzip multiple / many files under Linux?

I'm reposting the core of an excellent article by Vivek Gte on using wildcards with the unzip command on Unix: -


This is in specific response to an issue that one of my colleagues had earlier today, whilst trying to expand multiple WebSphere Application Server 8.5 installation packages on Linux: -

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?

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

No comments:

Post a Comment