Linux gunzip Command Tutorial with Examples – POFTUT

Linux gunzip Command Tutorial with Examples

.gz of gzip is very popular compression format used in Linux echo system. It is old compression algorithm but provides efficiency and speed during compression and decompression operations. Compression is very efficient file types like documents, text, some images etc. gzip compression algorithm also used in HTTP protocol to reduce traffic bandwidth.

Decompress Files with gzip Command

We can use gzip tool in order to decompress a .gz file. As we know there is single gzip library which is used by different commands and scripts. In the following examples we will completely use gunzip command. In this example we will decompress file named

$ gzip -d

Decompress with gunzip Command

gunzip command provides more simpler usage than gzip command. Because it is designed to decompress we do not need to provide any option. We will just issue the gunzip command and the file name like below.

$ gunzip

Keep Compressed and Decompressed File After Decompress

gunzip will remote compressed files after successfully decompress operation by default. If we need compressed file in the future we can avoid this behavior with -k option which means “keep this file after decompression”.

$ gunzip -k

Decompress Forcibly

Some times we can decompression with gunzip can create issues. This can prevent the compression because of created errors or warning. This errors and warning will prevent to complete decompression. We can provide -f force option which will complete decompression event some errors or warnings occurs.

$ gunzip -f

Display Information About Compressed File

Compressed files will have some attributes related with compression. We may need to list these attributes in order to get more information about the compression. We can list these attributed with  -l option.

$ gunzip -l
Display Information About Compressed File
Display Information About Compressed File

The following compression related attributes will be listed.

  • `Compressed Size` will show compressed file size
  • `Uncompressed Size` will show uncompressed file size
  • `Ratio` will show the compression ratio by dividing compressed size to uncompressed size
  • `Uncompressed Filename` will show filename in the archive.
LEARN MORE  How To Dump Mongodb By Using Mongodump Tool with Examples

Decompress Recursively

As we can compress recursively files in directories we may need to decompress them. Decompressing one by one entering to the directory is not feasibly. So we can decompress them recursively by using -r option. We will decompress all gz file in the directory named oldbackup.

$ gzip -r oldbackup/

Check Compressed File Integrity and Validity

Some file get corrupted during compression or after compression. If we try to decompress them we will get some warnings or errors. We can check their integrity and validity with -t option which means “test the .gz file”.

$ gzip -t oldbackup/

Verbose Output About Decompress Operation

Up to know we have not put a lot of screenshots because gzipcommand rarely output to the console. But if we need more information about the current operation we can use -v option to print a lot of information.

$ gunzip -v -r oldbackup/
Verbose Output About Decompress Operation
Verbose Output About Decompress Operation

Leave a Comment