Learn Gunzip Command in Linux Using Examples

1 min

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:

  • .gz
  • -gz
  • .z
  • -z
  • .tgz
  • -tgz

Here’s how.

Gunzip command to decompress files in Linux

The general syntax for the gunzip command is as follows:

gunzip [OPTIONs]....[FILEs]

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:

gunzip my_file.gz

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 
A basic Gunzip example
A basic Gunzip example

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

Wrapping Up

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.


Creator and author of debugpoint.com. Connect with me via Telegram, Twitter, or send us an email.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments