How to Unzip a .gz File on Linux: A Step-by-Step Tutorial

Working with compressed files is a common task in Linux environments, and .gz files are a widely used format for storing compressed data. Unzipping these files is essential for accessing their contents, whether it’s extracting data for analysis, installing software packages, or simply viewing text documents.

In this blog post, we will explore two primary methods for unzipping .gz files on Linux: the command-line approach using the tar commands and the graphical method utilizing file managers.

Method 1: Using the Graphical Method

Unzipping .gz files on Linux doesn’t always require diving into the command line. Most file managers provide a built-in graphical method for extracting compressed files, making the process straightforward and user-friendly.

Locating the .gz File

The first step is to locate the .gz file you want to unzip. Open your preferred file manager, such as Files or Nautilus, and navigate to the directory containing the .gz file.

locating .gz file

Right-Click and Unzip

Once you’ve found the .gz file, right-click on it to reveal a context menu. Look for an option labeled “Extract Here” or “Extract to”. Selecting either of these options will initiate the unzipping process.

Extracting to Current Directory

If you want to unzip the file to the current directory, simply select the “Extract” option from the context menu. The file will be extracted directly into the directory you’re currently viewing.

extracting gz file

Choosing the Destination Directory

If you want to unzip the file to a specific directory, choose the “Extract to” option from the context menu. A file selection dialog will appear, allowing you to choose the desired destination directory.

extracting to specific directory

Once you’ve selected the directory, click the “Extract” button to proceed.

Method 2: Using the tar Command

Unzipping a .tar.gz file in Linux involves using the tar command via the terminal. This command-line tool allows you to extract the contents of these compressed archives swiftly and efficiently.

Open a terminal window using ctrl + atl +T then us the cd command to navigate to the directory containing the .tar.gz file you wish to unzip. For instance, if the file resides in the Downloads directory, type cd Downloads.

locate the file in the terminal

Extracting the Files

Unzipping with Precision: Use the following command to extract the files:

tar -xvzf filename.tar.gz

Decoding the Command: Let’s break down this powerful command:

  • tar: The command itself, the key to unlocking the archive.
  • x: Instructs tar to extract the files from the archive.
  • v: Enables verbose output, providing a detailed list of the extracted files.
  • z: Decompresses the files using gzip, ensuring seamless extraction.
  • f: Specifies the filename of the archive, identifying the target file.

Examples of tar Command

Specifying a Destination Directory:

tar -xvzf filename.tar.gz -C /home/user/Documents

This command will extract the contents of filename.tar.gz to the /home/user/Documents directory.

Excluding Specific Files:

tar -xvzf filename.tar.gz -X file1 file2 file3

This command will extract the contents of filename.tar.gz but will exclude the files file1, file2, and file3.

Preserving File Permissions:

tar -xvzf filename.tar.gz -p

This command will extract the contents of filename.tar.gz and will preserve the original file permissions.

Decompressing Files Compressed with bzip2:

tar -xvjf filename.tar.bz2

This command will extract the contents of filename.tar.bz2, which is compressed with bzip2 instead of gzip.

Extracting Multiple Archives:

tar -xvzf *.tar.gz

This command will extract the contents of all .tar.gz files in the current directory.


Unzipping gz files is a common task in the Linux Operating System, and now you have the knowledge and skills to do it with ease. Whether you prefer the command-line power of the tar command or the visual simplicity of a graphical file manager, both methods are effective and straightforward.

Share your love

Newsletter Updates

Stay updated with our latest guides and tutorials about Linux.

Leave a Reply

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