How to Use Gzip on Linux?

28

Gzip is a common compression algorithm that allows you to compress a file while keeping the original file format, ownership, and timeline.

When you use the gzip command to compress a file or folder, it would have the same name as before, but with the extension.gz.

Syntax:

Text files, Tar archives, and websites are all compressed with Gzip.

Compress File Using .gz:

Enter the mentioned command to compress a single file with .gz:

A new zip file will be created with .gz extension.

Compress Multiple Files:

You can compress multiple files simultaneously, pass filenames as parameters. Run the below command:

$ gzip file1name file2name file2name

How to Use Gzip on Linux? 1618073338 580 How to Use Gzip on Linux

Keep Original File Save:

The original file will be deleted after creating the .gz file. Use –k option to keep the original file:

How to Use Gzip on Linux? 1618073339 705 How to Use Gzip on Linux

Alternatively, if you want to preserve the original file, you can use the -c option which allows gzip to write to an output file and pass it to a file.

$ gzip –c filename > filename.gz

Compress Every File in a Folder and its Subfolder:

Use the following command to compress all files in a folder and subfolders.

How to Use Gzip on Linux? 1618073339 69 How to Use Gzip on Linux

Decompress File Using .gz:

Use –d option to decompress .gz archive. Follow the below command:

How to Use Gzip on Linux? 1618073339 253 How to Use Gzip on Linux

Another way to decompress a .gz file is by using gunzip command:

Decompress Multiple Files:

We can decompress multiple files simultaneously using the command shown below:

$ -d file1name file2name file3name file4name.gz

How to Use Gzip on Linux? 1618073340 451 How to Use Gzip on Linux

How to Use Gzip on Linux? 1618073341 323 How to Use Gzip on Linux

Test Validity of File:

Use –t option to test the validity of the compressed file.

How to Use Gzip on Linux? 1618073341 560 How to Use Gzip on Linux

Change Compression Level:

You may use gzip to define compression levels ranging from 1 to 9. You can select between a smaller compression level that runs faster or a maximum compression level that takes longer to run.

Enter the following command to get a full compression at the lowest latency:

How to Use Gzip on Linux? 1618073341 959 How to Use Gzip on Linux

Enter the below-mentioned command to get minimum compression for a faster speed:

How to Use Gzip on Linux? 1618073342 23 How to Use Gzip on Linux

List the Content of the Compressed File:

Use –l option to show the statistics of the compressed ad uncompressed file.

How to Use Gzip on Linux? 1618073342 386 How to Use Gzip on Linux

Use the –v option with -l to get more detail of the compressed file.

How to Use Gzip on Linux? 1618073342 36 How to Use Gzip on Linux

Conclusion:

You may use gzip to compress a file and make it smaller. The gzip command can be used to either compress or decompress files. Multiple files can also be compressed or decompressed at the same time. We have used various options of gzip.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More