Gunzip Command in Linux
Introduction
The 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
The 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.
All the gzip
command-line arguments apply to gunzip
.
Pass the compressed file name as an input to gunzip
to decompress a .gz
file:
gunzip filename.gz
The command will rename, owner, mode, and timestamp the compressed file to its original values.
By default, gunzip
removes the compressed file after it has been decompressed. To keep the file, use the -k
option:
gunzip -k filename.gz
Use the -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
command:
gunzip file1.gz file2.gz file3.gz
Use the -r
option to recursively decompress all files in a particular directory:
gunzip -r directory
List the Compressed File Contents
When the -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:
Output
compressed uncompressed ratio uncompressed_name
146 141 9.2% filename
Use the -v
option for more verbose output:
gunzip -lv filename
Output
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?
The 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 .gz
extension.
Can gunzip
decompress multiple files at once?
No, the 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 gunzip
?
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 gunzip
?
Yes, you can use the -k
or --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
?
No, the 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
.
Does gunzip
work on directories or recursive file structures?
No, 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.
Conclusion
You can use the gunzip
command to decompress .gz files.
Visit the Gnu gzip
documentation page for further information on the gunzip
command.
If you have any queries, please leave a comment below and we’ll be happy to respond to them.