1

I have a directory where there are multiple folders, each of folder contains a .gz file. How can I unzip all of them at once?

My data looks like this

List of folders

A
B
C
D

In every of them there is file as

A
a.out.gz
B
b.out.gz
C
c.out.gz
D
d.out.gz
4

This uses gunzip to unzip all files in a folder and have the ending .out.gz

gunzip */*.out.gz

This will "loop"* through all folders that have a zipped file in them. Let me add an example:

A
a.out.gz
B
b.out.gz
C
c.out.gz
D
d.out.gz
E
e.out

Using the command above, a.out.gz b.out.gz c.out.gz d.out.gz will all get unzipped, but it won't touch e.out since it isn't zipped.

*this is called globbing or filename expansion. You might like to read some more about it here.

  • But what if i have multiple folders each of which contains zip file. How can i loop through all folders? – HoHoHo May 11 '16 at 11:43
  • the */*.out.gz will loop all folders (it's the */ part) – mazs May 11 '16 at 11:49
  • @HoHoHo as mazs point out, this does "loop". I've added some extra explanation and a link to a page which further explains the concept :) – forquare May 11 '16 at 11:53
0
find . -type f -name "*.gz" -execdir gunzip {} \;

the execdir option to find causes 'find' to 'cd' into each directory in turn and run the exec command (gunzip in this case) and then 'cd' back to the cwd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.