gzip
From NetBSD Wiki
The gzip(1) tool uses the LZ77 algorithm to compress or decompress files. When invoked with the gzip command, it will default to compression. It can also be invoked as gunzip, defaulting to decompression.
Contents |
Compressing
To compress a file, you can run:
$ gzip test.txt
This will replace test.txt with a compressed version of the file, called test.txt.gz.
Decompressing
To decompress, run:
$ gunzip test.txt.gz
The compressed version will then be replaced with the original test.txt.
The -d option to gzip has the sam effect as running gunzip.
$ gzip -d test.txt.gz
Writing to stdout
The gzip program can also be invoked as gzcat, in which case it will print the decompressed file on stdout.
$ gzcat test.txt.gz This is the content of test.txt
Using in a pipeline
Running gzip without any arguments will compress the data on stdin and write it to stdout. This way, it can be combined with tar or other programs in a pipeline. This will create a tarball from a directory:
$ tar cf testdir/ | gzip >testdir.tar.gz
and this will recreate the direcory from the tarball:
$ gunzip -c testdir.tar.gz | tar xf -
These pipelines are seldom used these days, because tar has an option (z) to automatically invoke gzip.
