TL;DR
To unzip GZ files in Linux, you can try out any of these three methods:
- Gunzip Command: Use the gunzip command to unzip GZ files by running gunzip filename.gz in the terminal.
- gzip -d Command: Unzip GZ files with the gzip -d command by running gzip -d filename.gz in the terminal.
- tar Command: Extract .tar.gz files using tar -xzf archive.tar.gz in the terminal, preserving the directory structure.
Learn the five effective ways to unzip GZ files in Linux with four third-party tools, three commonly used commands, five troubleshooting tips, and four best practices in the guide below.
Dealing with compressed files in Linux, especially GZ files, can be confusing. In this post, I’ll walk you through easy methods to unzip GZ files using different tools and commands. Whether you like using the command line or a graphical interface, there’s a method for you. You’ll also pick up some best practices for efficient file management. By the end, you’ll handle GZ files with confidence and improve your Linux skills.
What Are GZ Files?
GZ files are compressed files that use the gzip (GNU zip) compression algorithm. When you see a file with a .gz
extension, it means the file has been compressed to reduce its size. The gzip program takes a file, compresses it, and creates a new file with the .gz
extension.
GZ files are used for several important reasons:
- Save Space: Compressing files into GZ format makes them smaller. This helps save disk space, which is especially useful for storing large files or many files.
- Faster Transfers: Smaller file sizes mean faster upload and download times when transferring files over the internet. This is critical for speeding up data transfer and reducing bandwidth usage.
- Efficient Archiving: When you need to archive data, compressing files into GZ format keeps the archive more manageable by reducing its overall size.
- Data Integrity: Gzip includes checksums that help ensure the integrity of the data. If a file gets corrupted during transfer, you can often detect it.
How to Unzip GZ File in Linux in 3 Easy Ways
To unzip a GZ file in Linux, you have a few methods. First, use the gunzip
command by running gunzip filename.gz
in the terminal, which will decompress the file and remove the .gz extension.
Alternatively, you can use the gzip -d
command by typing gzip -d filename.gz
in the terminal to achieve the same result while preserving the original GZ file. For .tar.gz files, use the tar
command by executing tar -xzf archive.tar.gz
in the terminal to extract the contents while preserving the directory structure.
Here is the step-by-step guide for each method:
1. Gunzip Command
You can use the gunzip command to unzip GZ files in Linux. Follow these steps to easily extract GZ files using the command line:
- Launch the Terminal app on your Linux system and navigate to the directory where the GZ file is located using the cd command.
cd ~/directory-name
- Run the
gunzip
command followed by the name of the GZ file you want to extract. For example:
gunzip filename.gz

- If the extraction is successful, you should see a new file with the same name as the GZ file but without the .gz extension.

2. gzip -d Command
The gzip command is a powerful tool for file compression and decompression in Linux. By using the -d flag, you can decompress files that have been compressed with the GZ format. This method is straightforward and efficient for unzipping single GZ files.
- Start by opening your terminal.
- Use the cd command to navigate to the directory containing your .gz file.
cd /path/to/your/directory

- Run the following command to unzip the file.
gzip -d filename.gz
Replace filename.gz with the actual name of your GZ file.
The decompressed file will replace the original .gz file in the same directory. You should see filename (without the .gz extension).

3. tar Command
The tar command is a versatile utility for handling archive files. It is commonly used for creating and extracting .tar.gz files. Using tar, you can easily unzip these files while preserving the directory structure and other metadata.
- Launch your terminal application.
- Use the cd command to go to the directory containing your .tar.gz file.
cd /path/to/your/directory
- Run the following command to unzip the file.
tar -xzf archive.tar.gz
Replace archive.tar.gz with the actual name of your .tar.gz file.
The contents will be extracted to the current directory, preserving the original structure.

- Options and Flags:
- -x (extract): Tells tar to extract files from an archive.
- -z (gzip): Indicates that the archive is compressed with gzip.
- -f (file): Specifies the filename of the archive to work with.
- -C (directory): Allows you to specify a different directory to extract files to.
4. Use a Graphical User Interface (GUI)
If you prefer a more user-friendly approach, you can use a GUI tool to extract GZ files in Linux. Here’s how to extract GZ files using the default file manager in Ubuntu:
- Navigate to the directory where the GZ file is located using the file manager.

- Right-click on the GZ file and select Extract Here or Extract to from the context menu.

- When the extraction is complete, a newly created folder with the identical name as the GZ file should appear.

5. Use the Gunzip Command with Flags
To use the gunzip
command with flags, you can apply various options to modify its behavior. Here are some examples of how to use the gunzip
command to manage other operations for the GZ files.
- Use the
-c
option to write the decompressed output to standard output to decompress a file and specify the name of the output file.
gunzip -c file.gz > outputfile

- Another way to keep the original compressed file is to use the
-k
option with thegunzip
command. This flag preserves the original compressed file after decompression.
gunzip -k file.gz

- To force the decompression of a GZ file and overwrite the output file if it already exists, you can use the
-f
option.
gunzip -f file.gz

- To display information about a GZ file without decompressing it, you should use the
-l
option.
gunzip -l file.gz

Top 4 Third-Party Tools to Unzip GZ Files
In addition to command-line tools, you can also use other third-party tools for extracting GZ files. These tools provide a user-friendly interface that simplifies the extraction process and allows you to interact with GZ archives effortlessly. Here are some of the popular GUI tools available for extracting GZ files in Linux:
1. File Roller
File Roller, also known as Archive Manager, is a widely used GUI tool that comes pre-installed in many Linux distributions, including Ubuntu and Fedora. It supports various archive formats, including GZ files.
Using File Roller, you can easily unzip GZ files by simply selecting the archive and choosing the extraction location. It offers intuitive options for managing compression levels, file permissions, and other advanced settings.

2. PeaZip
PeaZip is a free and open-source cross-platform GUI tool that supports a wide range of archive formats, including GZ files. It offers a simple and intuitive interface with drag-and-drop functionality, making it easy to extract GZ files.
PeaZip also provides additional features like encryption, file conversion, and file integrity checking, enhancing the overall archiving and extraction experience.

3. Xarchiver
Xarchiver is a lightweight and user-friendly GUI tool for managing archives in Linux. It supports a wide range of archive formats, including GZ files. With Xarchiver, you can easily unzip GZ files by selecting the desired archive and choosing the extraction location.
It offers a simple and minimalistic interface, making it suitable to use if you prefer lightweight applications with basic archiving and extraction functionalities.

4. Ark
Ark is an archive manager for KDE desktop environments. It supports features such as drag-and-drop and previewing the contents of archives of various formats. Furthermore, this tool offers essential features for extracting GZ files, such as extracting to a specific directory, preserving file permissions, and handling password-protected archives.
It integrates well with the KDE Plasma desktop environment and provides seamless file management capabilities.

3 Commonly Used Commands to Manage GZ Files in Linux
In addition to the commands mentioned earlier in the article, several other useful commands can enhance your ability to work with GZ files in Linux. Here are some of them:
1. zgrep
zgrep
command is used to search for patterns in GZ files using regular expressions. It is similar to the grep
command, but works with compressed files. Here’s how you can use this command in the Terminal window:
zgrep "searchterm" filename.gz
The command will search for the specified “searchterm” within the given compressed file (filename.gz) and display any lines containing the search term in the standard output. This is helpful when you need to search for specific information within large, compressed files without having to manually decompress them first.

2. zmore
zmore
lets you view the contents of GZ files one screen at a time. It combines the functionality of more
(a text-paging tool) and gzip
(a file compression tool). Here’s an example of how to use more with the GZ files in Linux command prompt:
zmore filename.gz
This command will decompress the specified file (filename.gz) on-the-fly and display its contents one screen at a time in the terminal. You can navigate through the content using various keyboard commands.
For example, pressing Enter will display the next line, while the Space key presents the subsequent screen or page. To backtrack, simply press b to return to the previous screen, and when finished, hit q to exit zmore
mode and revert to the Linux command prompt.

3. zless
zless
command is similar to zmore
, but allows you to freely scroll up and down through the contents of the file using the arrow keys. This makes zless
a more versatile tool for examining large compressed files. To use zless
, simply type the following in the Terminal window:
zless filename.gz
When this command is executed in the terminal, the specified file is decompressed on-the-fly, and its contents are displayed for easy scrolling using the arrow keys. In addition to scrolling, you can employ other commands, such as press q to exit zless
mode and return to the command prompt in your Terminal window.

4 Best Practices to Manage GZ Files in Linux
By incorporating these Linux commands and practices, you can enhance your GZ file management, improve efficiency, and ensure the security and organization of your files. Here are some best practices for managing GZ files in Linux:
- 💾 Regular Backups: Back up all important GZ files to an external storage device or a cloud-based storage solution to prevent data loss in case of system failure or hardware malfunction. You can use commands like
rsync
ortar
with appropriate options to create automated backup scripts. - 🔄 Automation: Automate GZ file management tasks using tools like
cron
orsystemd
and scripting to save time, ensure consistency, and accuracy. Write scripts that handle the extraction, compression, and organization of GZ files and schedule them to run at specific intervals using cron or integrate them with systemd timers. - 🔒 Security: Maintain the security of GZ files by using encryption tools like GnuPG to encrypt sensitive files and setting appropriate file permissions and user access levels to preserve data confidentiality and integrity. Use commands like
gpg
to encrypt and decrypt GZ files andchmod
to set file permissions. - 📂 Organization: Organize GZ files in a separate directory, use descriptive file names and consistent naming conventions to make it easy to identify files and understand their contents. Keep a log of compressed and decompressed files to track their usage and manage disk space. Use commands like
mkdir
to create directories andmv
to move files to appropriate locations.
In a Nutshell
I’ve walked you through different methods to unzip GZ files in Linux in this article. Whether you use the command line, a graphical user interface, or advanced commands with flags, you now have multiple ways to extract your files efficiently.
If you’re eager to learn more, I recommend exploring into:
- Exploring how to extract tar files in Linux to handle another common archive format and expand your file management capabilities.
- Understanding the various uses of the tar command in Linux, giving you more flexibility in managing compressed files and directories.
- Fixing GPG issues related to no valid OpenPGP data found, which will help you troubleshoot and secure your encrypted data effectively.
Frequently Asked Questions
Can I use the same commands for unzipping GZ files on different Linux distributions?
How can I unzip multiple GZ files in Linux at once using a single command?
gunzip *.gz
to unzip all GZ files in the current directory. This command will decompress all files in the directory concurrently, saving you time and effort.Can I use gzip and gunzip commands on non-Linux platforms?
gzip
and gunzip
commands are also available on non-Linux platforms such as macOS and Windows. On macOS, these commands can be used in the Terminal app, similar to Linux. This means that if you’re familiar with using gzip and gunzip on Linux, you can easily use them on a Mac as well. On Windows, you can use gzip and gunzip commands through the Windows Subsystem for Linux (WSL). WSL allows you to run Linux commands and applications natively on Windows, making it a great option for using gzip and gunzip on a Windows machine. Alternatively, you can also use third-party tools like 7-Zip and WinRAR that support GZ file compression and decompression.