How to Unzip a .gz File in Linux

By 

Updated on

2 min read

Unzip Gz File

Gzip is a common compression format used on Linux and other Unix-like systems.

Files compressed with gzip usually end with .gz or .z.

This article explains how to unzip a .gz file in Linux with gzip or gunzip, and how to extract .tar.gz archives with tar.

Unzipping a gz File

On Linux and macOS, you can use the built-in gzip utility to decompress a .gz file.

Basic Syntax

Terminal
gzip -d file.gz

The command restores the compressed file to its original state and removes the .gz file after extraction.

Keep the Original .gz File

If you want to decompress the file without deleting the original compressed file, use the -k option:

Terminal
gzip -dk file.gz

Using gunzip

Another command you can use to decompress a .gz file is gunzip . This command is a convenience alias for gzip -d.

To open a .gz file with gunzip, run:

Terminal
gunzip file.gz

The command produces the uncompressed file and removes the .gz archive by default.

Extracting .gz Files Using a File Manager

If you use a desktop environment and are not comfortable with the command line, you can use your file manager to extract .gz files.

To open (unzip) a .gz file, right-click on the file you want to decompress and select “Extract” (or a similar option, depending on your file manager).

Windows users need to install additional software such as 7-Zip to open .gz files.

Extracting a .tar.gz File

The Gzip algorithm is designed to compress only a single file.

The tar file format allows you to combine multiple files into a single archive that can be compressed with the Gzip algorithm. This results in a compressed file that is smaller in size and easier to transfer or store.

Files ending in .tar.gz (or .tgz) are TAR archives compressed with gzip.

To extract a tar.gz file , use the tar command with the -xf option followed by the compressed archive name:

Terminal
tar -xf archive.tar.gz

The command automatically detects the compression type and extracts the contents to the current working directory .

Conclusion

You can unzip a .gz file in Linux with gzip -d or gunzip, and use gzip -dk when you want to keep the original archive. For .tar.gz files, use tar -xf to extract the archive contents.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page