Using gunzip Command in Linux
Learn to use the gunzip command in Linux with these practical examples.
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
optionsare used to tweak the default behavior of the utility.
filenameis 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:
For reference, here I want to decompress a Debian ISO file, so I will be using the following command:
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
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
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.
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:
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
Whereas the gunzip command is used to deal with archives ending with
I hope you will find this guide helpful and if you have any queries, let me know in the comments.