how can I extract multiple gzip files in directory and subdirectories?

You can use below command.

Go to the directory where your .gz file is and run command:

for f in *.gz ; do gunzip -c "$f" > /home/$USER/"${f%.*}" ; done

It will extract all file with original name and store it to current user home directory(/home/username). You can change it to somewhere else.

EDIT :

gunzip *.gz

This command also will work. But, by default, it replaces original file.


Option # 1 : unzip multiple files using single quote (short version)

gunzip '*.gz'

Note that *.gz 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)

for g in *.gz; do gunzip $g; done

The Source

EDIT :

I have just tried :

gunzip -dk *.gz

and it worked.

-d to decompress and k to keep original files.

Tags:

Gzip