The fastest way to open a .gz file
A .gz file is a compressed archive — think of it as a folder that has been squeezed down to take up less space. To open it in Linux, you use the gunzip command, which decompresses the file back to its original form. The command is simple: type gunzip filename.gz in your terminal, and the compressed file becomes a regular file you can read or use.
If you want to see what is inside the .gz file without permanently decompressing it, use zcat instead. This command reads the contents to your screen without changing the original file. For example, zcat filename.gz will display the file's contents in your terminal.
Most .gz files contain a single file, but some contain tar archives — which are collections of multiple files bundled together. If your filename ends in .tar.gz, you will need a slightly different approach, covered in the section below.
Key Takeaways
- Use gunzip filename.gz to decompress a .gz file and replace it with the original uncompressed version.
- Use zcat filename.gz to read the contents without decompressing, leaving the original file untouched.
- For .tar.gz files, use tar -xzf filename.tar.gz to extract all files at once in a single step.
- If you want to keep the original .gz file after decompressing, use gunzip -c filename.gz > newfilename to save the output with a new name.
Handling .tar.gz files (compressed archives with multiple files)
When a filename ends in .tar.gz, it contains multiple files bundled into a tar archive and then compressed. Do not decompress these with gunzip alone — use tar instead. The command tar -xzf filename.tar.gz extracts everything in one step. The flags mean: x for extract, z for gzip (the compression type), and f for file (the name that follows).
This creates a folder or set of files in your current directory. If you want to see what is inside before extracting, use tar -tzf filename.tar.gz instead. The t flag lists contents without extracting them.
Decompressing while keeping the original file
By default, gunzip deletes the .gz file after decompressing it. If you want to keep both the compressed and uncompressed versions, use the -c flag to send the output to a new file instead: gunzip -c filename.gz > filename. This reads the compressed file and writes the decompressed version to a file you name, leaving the original .gz untouched.
Alternatively, use cp filename.gz filename.gz.backup to make a copy of the compressed file before decompressing, so you have a backup if you need it later.
Using a graphical file manager instead of the terminal
If you prefer not to use the command line, most Linux desktop environments include a file manager that can handle .gz files directly. In GNOME Files (the default on Ubuntu), right-click the .gz file and select "Extract Here" or "Open With Archive Manager". KDE Plasma and other desktop environments have similar options in their context menus.
This approach works well for single files or .tar.gz archives. The extracted files appear in the same folder as the original compressed file. However, the terminal method is faster once you are comfortable typing the commands, and it gives you more control over where files end up.
Checking if a file is actually .gz before opening it
Sometimes a file has a .gz extension but is not actually compressed, or it is compressed with a different method. Use the file command to check: type file filename.gz and Linux will tell you what the file really is. If it says "gzip compressed data", gunzip will work. If it says something else — like "ASCII text" or "data" — the file may be mislabeled or corrupted.
You can also use gunzip -t filename.gz to test whether the file is valid gzip format without actually decompressing it. If the file is corrupted, gunzip will report an error instead of silently failing.
What to do if gunzip gives you an error
The most common error is "No such file or directory", which means the filename is wrong or the file is in a different folder. Check the exact spelling and make sure you are in the right directory by typing pwd to see your current location, then ls to list files in that folder.
If you see "not in gzip format", the file is not actually compressed with gzip, even if it has a .gz extension. Use the file command to see what it really is. If you see "Permission denied", you may not have read permission for the file — ask the file owner or use sudo if you are the system administrator, though this is rare for regular files.
Frequently Asked Questions
Can I open a .gz file on Windows or Mac?
Yes. Windows 10 and later can extract .gz files natively through File Explorer. On Mac, double-clicking a .gz file automatically decompresses it using the Archive Utility. Both systems also have third-party tools like 7-Zip or The Unarchiver if you prefer more control.
What is the difference between .gz and .zip?
.gz typically compresses a single file, while .zip bundles multiple files and compresses them together. .tar.gz combines tar (for bundling) with gzip (for compression), achieving what .zip does in one format. Linux prefers .tar.gz for software and backups; .zip is more common for sharing between Windows and Mac users.
Does gunzip work on .tar files that are not compressed?
No. Use tar -xf filename.tar for uncompressed tar files. The gunzip command only handles gzip compression. If a file ends in .tar, it is bundled but not compressed, so you extract it with tar alone, not gunzip.
Can I decompress multiple .gz files at once?
Yes. Use gunzip *.gz to decompress all .gz files in the current folder. The asterisk is a wildcard that matches any filename ending in .gz. Be careful with this command — it will decompress everything, so make sure that is what you want before running it.
What happens to the original .gz file after I decompress it?
By default, gunzip deletes the .gz file once decompression is complete. If you want to keep it, use the -c flag to write the output to a new file instead, leaving the original untouched.