Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I accidently gzip -rv directory and now all individual files is in .gz format. How do I undo this and gunzip all .gz files within the directory?

And how do I just gzip this whole directory?

I tried gunzip directory/*.gz but only gunzip the files in directory/ it doesn't gunzip directory beyond "directory".

share|improve this question

2 Answers 2

up vote 6 down vote accepted

To unzip your files, do the following:

find /yourdirectory -name *gz | xargs gunzip

This will unzip all files with the name *.gz find can find under the directory /yourdirectory.

For gzipping a whole directory, you need a tar container, as gzip can only compress individual files:

tar czvf archive.tgz /yourdirectory

If you want the (much slower but much more effective) bzip2 compression, use the j instead the z parameter:

tar cjvf archive.tbz2 /yourdirectory

Both commands will create a compressed archive, there is no need to do an additional compression step afterwards.

share|improve this answer
    
What command do you use exactly? –  Sven Mar 13 '12 at 11:05
    
sorry my bad spelling mistake. it worked! –  Maca Mar 13 '12 at 11:06
    
You just saved my arse! Thank you. –  Toggo Jul 2 at 21:28

Tar the directory first with tar -cf myarchive.tar myarchive/and compress it afterwards with gzip myarchive.tar.

You can unpack this afterwards with tar -xvf myarchive.tar.gz with newer versions of tar. With older versions you should add use -xvzf instead

share|improve this answer
    
Is there a way to undo all the .gz file? –  Maca Mar 13 '12 at 10:52
    
Switch into the directory and type gunzip *. –  Chris Mar 13 '12 at 10:56
    
The additional gzip step is unnecessary, and find exist. –  Sven Mar 13 '12 at 10:59
    
Certainly you can add a pipe to run it in one line, however I fail to see why you would downrate my reply as it is totally correct and a valid reply to one of Macas questions. –  Chris Mar 13 '12 at 11:05
    
It's for the recommendation to manually switch into the directory and do a gunzip. That's what the OP already did and wanted to avoid to do recursively. –  Sven Mar 13 '12 at 11:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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