gunzip command in Linux is used to decompress files compressed with the
gzip command. It takes a file with the
.gz extension as input and restores it to its original form. The
gunzip command is frequently used to decompress compressed files and work with their uncompressed versions.
In this tutorial, you will use the
gunzip command. We will also address a few FAQs on gunzip command in Linux.
Decompress Files with
gunzip command has the following general syntax:
gunzip [OPTION]... [FILE]...
gunzip is a bash script wrapper for the
gzip -d command on most Linux distributions, including Ubuntu, CentOS, and Debian.
gzip command-line arguments apply to
Pass the compressed file name as an input to
gunzip to decompress a
The command will rename, owner, mode, and timestamp the compressed file to its original values.
gunzip removes the compressed file after it has been decompressed. To keep the file, use the
gunzip -k filename.gz
-c option to write the output to the terminal. This allows you to keep the compressed file and decompress it to a different location if desired:
gunzip -c filename.gz > /directory/path/filename
Multiple files can be passed as parameters to the
gunzip file1.gz file2.gz file3.gz
-r option to recursively decompress all files in a particular directory:
gunzip -r directory
List the Compressed File Contents
-l option is used,
gunzip displays information about the compressed files:
gunzip -l filename.gz
The uncompressed file name, compressed and uncompressed sizes, and compression ratio will all be included in the output:
compressed uncompressed ratio uncompressed_name
146 141 9.2% filename
-v option for more verbose output:
gunzip -lv filename
method crc date time compressed uncompressed ratio uncompressed_name
defla 4a4a3fb5 Aug 29 15:40 146 141 9.2% filename
FAQs on Gunzip Command in Linux
How does the
gunzip command work?
gunzip command reads a file compressed with
gzip, restores it to its original state, and replaces the compressed file with the uncompressed version.
How do I use the
gunzip command to decompress a file?
To decompress a file using
gunzip, simply provide the name of the compressed file as an argument. For example,
gunzip filename.gz will decompress the
filename.gz file, resulting in the original file without the
gunzip decompress multiple files at once?
gunzip command can only decompress one file at a time. However, you can use wildcards like
* to decompress multiple files matching a pattern, such as
gunzip *.gz to decompress all
.gz files in the current directory.
What happens to the compressed file after decompression with
By default, the
gunzip command removes the compressed file after decompression, keeping only the uncompressed version.
Can I keep the compressed files when decompressing them with
Yes, you can use the
--keep option with the
gunzip command to keep the compressed file after decompression. This option will preserve both the compressed and uncompressed versions.
Can I see the progress during decompression with
gunzip command does not provide an option to display the progress of decompression. If progress tracking is desired, you can use the
pv command in combination with
gunzip work on directories or recursive file structures?
gunzip is designed to decompress individual files and does not support decompressing directories or recursively decompressing files within a directory structure. For compressing and decompressing directories, tools like
tar are commonly used in combination with
gzip or other compression algorithms.
You can use the
gunzip command to decompress .gz files.
Visit the Gnu
gzip documentation page for further information on the
If you have any queries, please leave a comment below and we’ll be happy to respond to them.