Linux – Gzip mistake with directory

gziplinux

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

Best Answer

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.