Compressing data with gzip
The gzip application is a common compression format in the GNU/Linux platform. The gzip, gunzip, and zcat programs all handle gzip compression. These utilities only compress/decompress a single file or data stream. They cannot archive directories and multiple files directly. Fortunately, gzip can be used with both tar and cpio.
How to do it...
gzip will compress a file and gunzip will decompress it back to the original:
- Compress a file with
gzip:
$ gzip filename $ ls filename.gz
- Extract a
gzipcompressed file:
$ gunzip filename.gz $ ls filename
- In order to list the properties of a compressed file, use the following command:
$ gzip -l test.txt.gz compressed uncompressed ratio uncompressed_name 35 6 -33.3% test.txt
- The
gzipcommand can read a file fromstdinand write a compressed file tostdout.
Read data from stdin and output the compressed data to stdout:
$ cat file | gzip -c > file.gz
The -c option...