Gzip Command Tutorial For Linux


Gzip is actually a file format which is a compressed file. There is also a tool named gzip which is used to compress and decompress files. Gzip is developed in 1992. It use DEFLATE algorithm with LZ77 and Huffman coding.

gzip Command Help

gzip command provides different options. These options and help information can be listed with the -h option like below.

$ gzip  -h
Help
Help

Compress File with gzip Command

Gzip can only compress files. It cannot compress multiple files folder or folders. Gzip command is generally used with tar command. We will only provide the file to be compressed. In this example, we will compress thefile.txt . The output file name will be the same with just adding .gz extension.

$ gzip thefile.txt
Compress File
Compress File

List Compressed File Contents with gzip Command

Compressed file contents can be listed without decompressing them. We will use -l option. In the example, we want to list thefile.txt.gz compressed file settings. There is also information about compressed size,  file ratio, uncompressed_name, etc.

$ gzip -l thefile.txt.gz

Higher Compression Rate with gzip

There are levels that are used to set compression ration, compressed file size, and compression duration. Higher-level compression will need more compression time but generally creates less file size. This is a trade-off. We will use -9 or --best options to specify.

$ gzip -9 thefile.txt
Higher Compression Rate
Higher Compression Rate

Faster Compression with gzip

Another option for compression is faster compression. Actually this is the reverse of the higher compression rate. The compression duration will be less but the size will be higher than the default compression rate. We will use -1 or --fast .

$ gzip --fast thefile.txt
Faster Compression
Faster Compression

Decompress File

Files can be decompressed with gunzip command or with -d parameter. gunzip is actually the alias of gzip -d .

$ gzip -d thefile.txt.gz
Decompress File
Decompress File

LEARN MORE  7z Command Tutorial With Examples To Compress And Extract Files In Linux

1 thought on “Gzip Command Tutorial For Linux”

Leave a Comment