The Gunzip command helps you to decompress .gz, -gz, .z, -z files compressed using gzip or other similar compression utilities.
I explained how to compress a file using gzip or zip command in earlier articles which create compressed files ending with .gz, -gz, .z or -z. If you want to unzip those files, you can use the gunzip command.
Gunzip command can automatically detect the compression types of the file and is able to decompress the following file types:
Gunzip command to decompress files in Linux
The general syntax for the
gunzip command is as follows:
The options are similar to gzip command line options. In fact, gunzip is a wrapper to the gzip -d command. So, to decompress a simple file, you need to provide the file name as an argument, as shown below:
The output of the above command is a decompressed file with its original name, owner, mode and timestamp.
When you run the above command, the gunzip command will delete the zip file. This is the default behaviour. To keep the original compressed file, use the option -k.
gunzip -k my_file.gz
You can also decompress multiple files by specifying them over the argument:
gunzip -k my_file1.gz my_file2.gz my_file3.gz
To decompress the files to a different directory, use the -c option, which writes it to the output and uses the redirection with the target path.
gunzip -k my_file.gz > /home/Downloads
If you have a folder with hundreds of compressed .gz files, you can use the -r option to decompress all files recursively.
gunzip -r /home/Downloads/zip_files
Like the gzip command, you can list the compression ratio, size of compression and other details using the -l option. You can pair it with -v verbose option for comprehensive details.
gunzip -lv my_file.gzip
In conclusion, the gunzip command allows you to decompress .gz files and you can use all the similar options of the compression tool gzip. To learn more, visit the GNU gzip documentation page (including gunzip).
For any questions, do let me know in the comment box below.
This article is part of the Linux command learning series.