2

I'm new to the gzip command, so I googled some commands to run so I can gzip an entire directory recursively. Now while it did that, it converted each of my files to the gzip format and added .gz to the end of each of their filenames.. is there a way to ungzip them all, one by one?

2 Answers 2

6

There are essentially two options for going through the whole directory tree:

Either you can use find(1):

find . -name '*.gz' -exec gzip -d "{}" \;

or if your shell has recursive globbing you could do something like:

for file in **/*.gz; do gzip -d "$file"; done

0
0

For one file at a time you can use:

gzip -d file.gz

For multiple files you can use:

for i in *.gz; do gzip -d $i; done
10
  • I have a lot of files, so this would take way too long.
    – PaulBGD
    Sep 20, 2014 at 21:05
  • @PaulBGD , My mistake, I misunderstood "is there a way to ungzip them all, one by one?" <-- one by one.... Anyway, I've updated the answer to include multiple files.
    – Simply_Me
    Sep 20, 2014 at 21:08
  • Is there a way to make it recursive as well?
    – PaulBGD
    Sep 20, 2014 at 21:11
  • @PaulBGD can you please give an example of recursive scenario? It's not clear to me. The current for loop will extract all of the compressed files in a given folder/path.
    – Simply_Me
    Sep 20, 2014 at 21:13
  • 1
    @Simply_Me OP said gzip and only .gz so what's tar and .tar.gz doing in this answer?
    – user
    Sep 20, 2014 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .