How to on Linux: Unzip a .gz File

How to on Linux: Unzip a .gz File

In this tutorial, we’re going to show you how to unzip a .gz file on Linux. These instructions will work on any Linux distro, even on a Mac.

We previously wrote about how to zip files on Linux, so now we’re going to show you how to unzip a GZ file.

TL;DR: In short, you just need to use the “gunzip” command and run:

gunzip <file.gz>

We’ll go into detail and show more examples with more options below.

What is a GZ file?

A GZ file is a single file compressed using the gzip (GNU zip) compression method. All .gz files are single files, they are not archives.

What you’ll need to “unzip” a .gz file

You’ll just need access to the Terminal (CLI), or GUI access, and access to the file itself.

These instructions will work on all Linux distros, including, but not limited to:

The commands below will work for .z files too.

How to unzip a GZ file on Linux via the CLI

There are multiple ways to unzip a gz file on Linux. We’ll show all options below.

How to unzip a .gz file using gzip

You can use the gzip utility that’s pre-installed on most Linux distros.

The basic syntax is:

gzip [options] <file.gz>

The option used for decompressing is -d. So to unzip a file, the syntax is:

gzip -d <file.gz>

This command will decompress/uncompress/unzip the .gz file, and delete the .gz file.

If you have a Terminal window opened in the directory the .gz file (for example, notes.txt.gz) is located in, you need to run:

gzip -d notes.txt.gz

If it’s in a different directory, (for example /home/random/notes.txt.gz) you’ll need to run:

gzip -d /home/random/notes.txt.gz

How to unzip a .gz file without removing the .gz file

If you’d want to keep the compressed file, you need to use the -k (–keep) option, like:

gzip -dk <file.gz>

This command will unzip the .gz file and keep the .gz file itself, along with the original gzipped file.

How to unzip a gz file using gunzip

The “gunzip” is just an alias for the “gzip -d” command, it’s easier to remember and use. To decompress a .gz file with the gunzip command, you can use this syntax:

gunzip <file.gz>

For example, if you need to decompress the file notes.txt.gz, you’ll need to run:

gunzip notes.txt.gz

gunzip just replaces “gzip -d” from all previous commands.

You can get more options and help with the gzip command by running the following command:

gzip -h

How to unzip a .tar.gz file

A .tar.gz file is actually a .tar archive/directory that’s compressed. So, a directory is zipped into a .tar file and the .tar file itself is zipped into a .gz file.

To unzip a .tar.gz file, you’ll need to use the tar command. We can write a whole tutorial about that command, but for the purposes of this tutorial, just use this syntax:

tar -xvf <archive.tar.gz>

For example, if you had a file/archive named wordpress.tar.gz, you’ll need to run this command to unzip it in the current directory:

tar -xvf wordpress.tar.gz

How to unzip a GZ file on Linux via GUI

If you’d like to use the Graphical User Interface (your desktop environment), you can extract/unzip/uncompress a .gz file by right-clicking on the file and clicking on “Extract Here”. It’s that simple.

Locate the file you want to unzip, right-click on that file, and left-click on “Extract Here”.

how to unzip gz file

This will unzip the “LinuxStans.html.gz” file to “LinuxStans.html” in the current directory. If you’d like to extract it to a different directory, just select the “Extract to…” option, right below “Extract Here”.

This screenshot is from Ubuntu 22.04, but the method is pretty similar to any other distro.

That’s it. If you have any issues with unzipping a .gz file, leave a comment below.

Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “How to on Linux: Unzip a .gz File”