Open In App

How to Unzip (Open) Gz File

Last Updated : 19 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

If you have been using Linux for some time, you must have come across a “gz” file. Have you ever wondered, what is it and how do you actually open it?

Worry not, in this article, we deep dive into the details of gz file and help you overcome your doubts about it.

What is gz file?

Remember the old compressed zip files, gz files are similar to that. gz is also a file format for creating compressed files using the GNU zip compression algorithm also known as gzip. A good thing about this approach is that gzip compression is lossless, hence, the data is not lost during compression and this makes it ideal for packaging software on Linux so that their sizes can be reduced for lower network loads, that too without any data loss. It uses the Lempel-Ziv encoding (LZ77) algorithm for compression.

However, gzip does have one drawback it can’t really compress multiple files at once, so we need to use gzip along with tar if we want to compress multiple files.

How to open gz file

Now that we know what gz files are, let’s look into ways of unzipping or opening them. Since after all, it’s only after decompression that the files are of any use or not. Also since we are looking at gz files which are under the GNU umbrella, opening these files on Linux is really easy to do and with a lot of options to choose from. That said, even if you are on another system, you will still be able to open these files, just the methods will be different.

Method 1: Using the gzip command

Step 1 : Use they key combination Ctrl+Alt+T to open the terminal. The terminal is a command line interface that allows for more direct control over the system. You can also open it from the application menu if you so choose.

Ctrl+Alt+T

Step 2 : Run the gzip command with the -d flag to decompress the gz file. Here -d is the shorthand for -decompress. Using this command allows us to decompress the file with ease in a single step. As we will be able to see, the file is now decompressed. However as we can also notice, running gzip removes the compressed file after decompression. This means only the uncompressed file will remain after execution of this command and you will loose access to the compressed file.

gzip -d filename.gz
ok4

Gzip command in action

Method 2 : Using graphical archive manager

Step 1 : First of all locate the file that you want to extract. For this, open up your file explorer, which is the app you use to navigate through the file system. On Ubuntu this file system is Nautilus. To open it search for files in the application menu and click on the folder like icon.

ok1

Locate the compressed .gz file

Step 2 : Now, that we have located our files. We can go ahead and start with the actual extraction of the file. For this, right click on the file, this opens up a context menu. Now in this menu locate and click on the option that says “extract” to extract the gz file.

ok2

Click on extract from the right click menu

Step 3 : Now as we can notice a new uncompressed file will appear in the file explorer. Now you can just double click on the file to open it. A good thing about this method is that it will not remove the compressed file, after its done extracting the file. Therefore you will still have access to both the compressed and uncompressed version of the file after you are done extracting.

ok3

Extracted file is now visible in the file explorer

Method 3 : Using gunzip command

Step 1 : Use the application menu to open the terminal, or use the shortcut Ctrl+Alt+T to do the same. This will open up a terminal window or in other words, a command line interface from where you can run commands and utilities on your system.

Ctrl+Alt+T

Step 2 : Now, run the following gunzip command to decompress the xz file. This command is functionally the same as using gzip. And this command will also remove your gz and replace it with the decompressed file. So, this too will make the compressed file inaccessible after execution and you will be left only with the uncompressed file at the end.

gunzip filename.gz
ok5

Using gunzip command to decompress xz files

Method 4 : Using tar command [ONLY for compression in the tar.gz format]

If you have been on Linux for sometime you might have come across another file extension .tar.gz. This is a tarball, (here tar stands for tape archive) essentially it is a collection of files that have been combined into a single compressed file using the gzip compression algorithm used by normal gz. This overcomes the big limitation of standard gz, and allows for compression of entire folders.

Now that we know what is tar.gz, Lets learn how to open it as well. This can be done using the exact same method as method 2 using the file manager and also using the command line. Here we will focus at opening the file using command line, since the graphical method is self explanatory and follows the exact same steps as we have already discussed.

Step 1 : Locate your compressed folder with tar.gz extension. For this search for the application called files on Ubuntu and click on the folder like icon that will appear. This opens the file explorer using which you can locate your tar.gz file. An important thing to note here, is that not all Linux distros use the same file manager, Ubuntu uses nautilus, your distro might use something else. In any case, your distro should come will a graphical app to open files and navigate through the file system.

ok6

a tar.gz file

Step 2 : Now that we have verified that our file is a tar.gz file and not a simple gz file. Open up the terminal using Ctrl+Alt+T or the application menu. This opens up a command line interface where you can access various command line utilities and system information.

Ctrl + Alt + T

Step 3 : Now run the tar command with the -xvf flag. Here “x” flag is for extract, “v” is for verbose so we see the command output in terminal and “f” is to indicate that we wan to extract the following file. This command will decompress the folder in the same location, display the output in console and at the same time also retain the compressed folder. So you will still have access to the original compressed file after execution of the command.

tar -xvf filename.tar.gz
ok7

Using tar -xvf to extract a .tar.gz file

Conclusion

As we have seen over the course of this article, xz files are nothing special. They are just a way of storing and compressing files. And while you’re on Linux, you don’t need to worry much. Most of the newer graphical distros like Ubuntu and Linux Mint come with built in tools to decompress files using a GUI. And even if you’re using a distro that does not have built in tools for it, you can just use the commands we discussed above.So next time you see a gz file or a tarball don’t panic, they are not a hassle. They are fun to use and easy to extract.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads