Skip to main content
Commands

Using gunzip Command in Linux

Learn to use the gunzip command in Linux with these practical examples.

Sagar Sharma

Warp Terminal

Got a .gz file? It is a gzip-compressed archive file. Gzip reduces the file size better than the simple zip archive.

Now, to unzip a file, you have the unzip command in Linux. But you cannot use it on the gzip files.

To extract a .gz file, you need gunzip command.

It has a basic syntax:

gunzip <options> filename

Where,

  • options are used to tweak the default behavior of the utility.
  • filename is where you append the file for decompression.

Let me share some examples of using gunzip on Linux.

Decompress files using gunzip on Linux

To decompress a file, all you need to do is append the filename to the gunzip command:

gunzip compressed_file

For reference, here I want to decompress a Debian ISO file, so I will be using the following command:

gunzip debian-testing-amd64-DVD-1.iso.gz

But if you notice carefully, it replaces the original file so what if you want to have both?

Decompress files while keeping the original intact

To keep the compressed file while using the gunzip command, you will have to use the -k option:

gunzip -k compressed_file

And as you can clearly see, the original compressed file is as it is in addition to the decompressed file I got here.

Unzip files recursively

Imagine that your gzipped file has other gzipped files inside it. By default, the extracted file will have zipped folders inside it.

So if you want to decompress files recursively, you can specify the directory to the gunzip command with the -r option:

gunzip -r directory_name 

For example, Here I want to decompress every compressed file available inside the compressed directory so I will be using the following:

gunzip -rv compressed/

And if you are curious, the additional -v option was used to have verbose output.

Force decompression

While decompression, if you have the file with the same name, it will ask you whether you want to override it or not:

And if you want to skip that warning, you can use the -f option to proceed for forceful decompression:

gunzip -f compressed_file

As you can see, when I used the -f option, it skipped the question part. A good solution if you are writing a script!

But wait! What about the unzip command?

Well, we have already covered how you can use unzip command with practical examples:

Unzip command in Linux: 8 Practical Examples
Got a zip file in the terminal? Learn how to use the unzip command in Linux with these practical examples.

What's the difference between unzip and gunzip you may ask?

Well, in the most simple terms, the unzip command is used to extract files with .zip extensions.

Whereas the gunzip command is used to deal with archives ending with .gz, .tar, etc.

I hope you will find this guide helpful and if you have any queries, let me know in the comments.

Sagar Sharma