The other name of the tar file is tarballs and these files are mostly used in the Linux/ubuntu operating system. The “tar.gz” files are in the compressed format and have one or more than one file. The “gzip” is the main algorithm used to make the tar.gz file. The memory of this tar.gz file is less as compared to uncompressed counterpart files.      

What Command Do I Need to Unzip/Extract a .tar.gz File?

To unzip the “.tar.gz” file from the Ubuntu/Linux terminal first install the “tar” command on the Linux by using the terminal. Open the Linux terminal using the shortcut key “Ctrl+Shift+T” from the keyboard. Now for the installation execute the command.

sudo apt-get install tar

In the above command, 

  • sudo” command is used to attain the root rights in the Linux terminal.
  • apt-get” command is used to access the advanced packages to install and remove files in the Linux terminal.

To check the version of your tar command execute the below given command

tar --version

Now the tar command has been installed on your Linux/Ubuntu operating system and before extracting the file by this command you need to make the “.tar.gz” file by executing the below given command.

tar -czvf project.tar.gz file name

In the above command 

  • -c” creates the project.
  • -z” compressed the file according to the method.
  • -v” calls the tar to perform the function.
  • -f project.tar.gz” gives the name of the specified file.

In the below figure, it is clearly shown that the “Test.tar.gz” file is created by executing the above command.

Now to unzip or extract the “.tar.gz” file the command to be executed is given as.

tar -zxvf Testfile.tar.gz

Make a little modification to the above command and execute to unzip or extract the files from “tar.gz” file. 

tar -xvzf Testfile.tar.gz

If you want to extract the files that are lying in the subdirectory then execute the below command in the Linux/Ubuntu terminal.

tar -xvzf Test.tar.gz Data/Testfile.txt

To extract the list of files from a “tar.gz” file you need to execute the below command.

tar -xf filename.tar.gz file1 file2

In the above command “-xf” give the command to “tar” to extract the mentioned file.

The figure shows that the two files “Test.odt” and “Testfile.txt” are extracted from a “files.tar.gz” file. 

Now extract the file with the specific extension such as .js file which is a javascript file, .mp4 file which is a video, and .odt file which is a text file in Linux/Ubuntu using the “–wildcards” with tar command. For example, in our case, .odt file is extracted by executing the below-given command. 

tar -xf filename.tar.gz --wildcards '*.odt'

The figure below shows the output results of the above command. 

Now if you want to list the data of the “tar.gz” file then execute the below given command.

tar -tf Test.tar.gz

In the above command “-tf” gives the output the list of data in the “tar.gz” file.

Now to view the extra information of the files such as its read write capability, owner name and date of creation in the “tar.gz” file then execute the below given command.

tar -tvf filename.tar.gz

In the above command “-tvf ” provides the extra information related to the files lies in the “tar.gz” file. 

Now if you want to extract the files from a specific pipeline then execute the below given command in the Linux/Ubuntu terminal.

wget -c https://download.blender.org/source/blender-2.80.tar.gz -O - | sudo tar -xz

In the above command “blender” is downloaded using the “wget” command and gives the output to the “tar”. 

By executing the above command the output blender directory is extracted from the online blender tar.gz source.

Conclusion

To unzip or extract the “tar.gz” files in the Linux/Ubuntu operating system there are different command  available to execute in the terminal such as “tar -czvf project.tar.gz file name”, “tar -xvzf Test.tar.gz Data/Testfile.txt”, “tar -xf filename.tar.gz –wildcards ‘*.odt’”, and “tar -tvf filename.tar.gz”. Each command perform the specific function for the “tar.gz” file for example “tar -tvf filename.tar.gz” command give the output as list of files in a “tar.gz” file with some extra information such as the owner name, read write capability, date of creation.