Thursday, 4 October 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

1 comment:

Dave Hay said...

Note that, on my Mac, the important key is the single quote key ( ' ) - located on the right-hand side of my UK keyboard, shifted down from the double quote key ( " ).

The WRONG key is the other quote-like key ( ` ) which is on the left-hand side of my keyboard, shifted down from the circumflex ( ~ ).

Make sense ?

Use this -> '
Not this -> `