Gunzip Command in Linux

Posted 

2 min read

Gunzip is a command-line tool for decompressing Gzip files.

Gzip is one of the most popular compression algorithms that reduce the size of a file and keep the original file mode, ownership, and timestamp.

By convention, files compressed with Gzip are given either the .gz or .z extension.

In this tutorial, we will explain how to use the gunzip command.

Decompressing Files with gunzip

The general syntax for the gunzip command is as follows:

gunzip [OPTION]... [FILE]...

On most Linux distributions, such as Ubuntu, CentOS, and Debian, gunzip is a bash script wrapper to the gzip -d command.

All gzip command line options are applicable gunzip.

To decompress a .gz file with gunzip, pass the compressed file name as an argument:

gunzip filename.gz

The command will restore the compressed file to its original name, owner, mode and timestamp.

By default, once decompressed, gunzip will remove the compressed file. Use the -k option to keep the file:

gunzip -k filename.gz

To write the output on the terminal use the -c option. This allows you to keep the compressed file and optionally decompress it to another location:

gunzip -c filename.gz > /directory/path/filename

The gunzip command also accept multiple files as arguments:

gunzip file1.gz file2.gz file3.gz

To recursively decompresses all files in a given directory, use the -r option:

gunzip -r directory

List the Compressed File Contents

When used with the -l option, gunzip shows information about the given compressed files:

gunzip -l filename.gz

The output will include the uncompressed file name, the compressed and uncompressed size, and the compression ratio:

         compressed        uncompressed  ratio uncompressed_name
                146                 141   9.2% filename

For more verbose output, use the -v option:

gunzip -lv filename
method  crc     date  time           compressed        uncompressed  ratio uncompressed_name
defla 4a4a3fb5 Aug 29 15:40                 146                 141   9.2% filename

Conclusion

The gunzip command allows you to decompress .gz files.

For more information about the gunzip command, visit the Gnu gzip documentation page.

If you have any question, please leave a comment below.