From LQWiki
Jump to: navigation, search

The gzip package compresses and decompresses data using a patent-free compression algorithm, LZ77. When called as gunzip or with the -d option, this utility can be used to decompress files created with: compress(.Z), gzip(.gz,.tgz), and zip(.zip) (first file only). When called as zcat or with the -dc options, displays the specified gzip compressed file without decompressing the file. The same program is installed as gzip, gunzip, and zcat.


$ gzip [options] filename
$ gunzip [options] filename
$ zcat [options] filename    # Same as gunzip -c

Man page



$ gzip bigfile.txt

Compresses the specified filename. The compressed file is called bigfile.txt.gz

$ gzip -9 bigfile.txt

Compresses the specified file using the compression method that yields maximum reduction in size. The compression tradeoff between size and speed can be modified by using the form:

$ gzip -n bigfile.txt

where n=9 is the slowest, but best compression, and 1 is the fastest, and worst compression. This can be useful to tune the speed of compression of extremely large files (on relatively small ones this option can always be used with little performance tradeoff), where compression is not the greatest concern.

$ gzip -r /home/lala/docs

Compresses all the files seperately in the specified directory and all of its associated subdirectories. The "r" stands for recursive, and this option to recurse through all subdirectories is a common one for many Unix utilities.

$ zcat file.txt.gz |less

Decompress file.txt.gz and pass the data on to less for viewing. Don't remove the original file.

$ tar -xvzf file.tar.gz

The -z option tells tar to call gzip for decompressing the tarball.

See also