Compressed files take up less disk space and download from the network faster than large, uncompressed files. You can compress files in Linux with the freely available Gzip utility. By default, compressed files are given a “.gz” extension.
Gzip provides lossless compression. The original data can be fully recovered when decompressed. It is based on the DEFLATE algorithm, which uses a combination of the LZ77 algorithm and the Huffman algorithm.
To compress a file, type the following command “gzip filename.txt” at the shell prompt. The file will be compressed and saved as “filename.txt.gz”. The original file will be deleted.
To expand the compressed file, type the command “gunzip filename.txt.gz” The file “filename.txt.gz” will be removed and replaced by “filename.txt”.
Gzip itself “cannot” compress multiple files at once, so it is better to compress them first.
If you want to save the original file, use the “-k” switch. The command “gzip -k archive.tar” not only creates a compressed archive “archive.tar.gzip”, but also saves the source “archive.tar”.