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
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
$ gzip thefile.txt
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
--best options to specify.
$ gzip -9 thefile.txt
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
$ gzip --fast thefile.txt
Files can be decompressed with
gunzip command or with
-d parameter. gunzip is actually the alias of
gzip -d .
$ gzip -d thefile.txt.gz
1 thought on “Gzip Command Tutorial For Linux”