3

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".

6

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.

  • 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
0

This would do the trick:

gzip -d -r directory
-3

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

  • 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

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.