Compressing data with gzip
gzip is a commonly used compression format in the GNU/Linux platform. It is one of the utilities (such as gzip
, gunzip
, and zcat
) that handle gzip compression. However, gzip
can be applied only on a single file or data stream. This means that it cannot archive directories and multiple files. Hence, we must first create a tar
archive and compress it with gzip
. Let's see how to operate with gzip
.
How to do it...
gzip
can be used both to compress files and decompress them back to the original:
In order to compress a file with
gzip
use the following command:$ gzip filename $ ls filename.gz
Extract a
gzip
compressed file as follows:$ gunzip filename.gz $ ls file
In order to list out the properties of a compressed file use:
$ gzip -l test.txt.gz compressed uncompressed ratio uncompressed_name 35 6 -33.3% test.txt
The
gzip
command can read a file fromstdin
and also write a compressed file intostdout
.Read data from
stdin
and output the compressed...