gzip Command: Tutorial & Examples

Compress or decompress files

The gzip command is a Unix utility that compresses and decompresses files. It is a common file compression utility that uses the GNU zip (gzip) algorithm to compress and decompress files.

To use the gzip command to compress a file, you can specify the name of the file you want to compress as an argument. For example:

gzip file.txt

This will compress the file file.txt and create a new compressed file called file.txt.gz.

To decompress a file that has been compressed with gzip, you can use the -d option. For example:

gzip -d file.txt.gz

This will decompress the file file.txt.gz and create a new decompressed file called file.txt.

The gzip command has several options that allow you to customize its behavior, such as specifying the level of compression, specifying the output file name, and displaying the progress of the compression or decompression process.

For example, you can use the following command to compress a file with the highest compression level:

gzip -9 file.txt

Although gzip is more or less the standard compression utility, its performance is not very good, especially when the compression level is high. We would recommend, that you use the zstd command instead which supports much higher compression speeds and generally better compression.