How to Use the gunzip Command in Linux

By 

Updated on

3 min read

Linux Gunzip Command

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

Gzip is one of the most popular compression algorithms that reduces the size of a file while preserving the original ownership, permissions, and timestamps.

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

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

Basic Syntax

The general syntax for the gunzip command is as follows:

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

On most Linux distributions, such as Ubuntu, CentOS, and Debian, gunzip is a Bash script that calls the gzip -d command.

All gzip command-line options work with gunzip as well.

Decompressing Files with gunzip

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

Terminal
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:

Terminal
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:

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

The gunzip command also accepts multiple files as arguments:

Terminal
gunzip file1.gz file2.gz file3.gz

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

Terminal
gunzip -r directory

List the Compressed File Contents

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

Terminal
gunzip -l filename.gz

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

output
         compressed        uncompressed  ratio uncompressed_name
                146                 141   9.2% filename

For more verbose output (compression method, CRC, timestamp, etc.), use the -v option:

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

Reference Table

DescriptionCommand
Decompress and delete the .gz filegunzip filename.gz
Decompress and keep the .gz filegunzip -k filename.gz
Output to terminal/redirectgunzip -c filename.gz > newfile
Decompress multiple .gz filesgunzip file1.gz file2.gz ...
Recursively decompress directorygunzip -r /path/to/dir
List contentsgunzip -l filename.gz
Verbose listinggunzip -lv filename.gz
Test file integrity (no extract)gzip -t filename.gz
Force decompression (even if file exists)gunzip -f filename.gz
Decompress to stdout and keep originalgunzip -kc filename.gz

Conclusion

The gunzip command is a powerful tool for decompressing .gz files. You can use it to extract a single archive, inspect its contents, or decompress multiple files at once.

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

Questions? Feel free to drop a comment below!

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page