Home » Linux Command » How to Extract (Unzip) Tar Gz File

How to Extract (Unzip) Tar Gz File

Update on:
Sep 2, 2021

If you’re roaming the open-source world, chances are high you encounter .tar.gz information regularly. Open-source packages are usually out there to obtain in .tar.gz and .zip codecs.

The tar command is used to create tar archives by changing a bunch of information into an archive. It helps an enormous vary of compression applications akin to gzip, bzip2, lzip, lzma, lzop, xz and compress. Tar was initially designed for creating archives to retailer information on magnetic tape which is why it has its title “Tape ARchive”.

Gzip is the most well-liked algorithm for compressing tar information. By conference, the title of a tar archive compressed with gzip ought to finish with both .tar.gz or .tgz.

Briefly, a file that ends in .tar.gz is a .tar archive compressed with gzip.

The tar command can be used to extract tar archives, show an inventory of the information included within the archive, add further information to an current archive, in addition to numerous different kinds of operations.

On this tutorial, we are going to present you the best way to extract (or unzip) tar.gz and tgz archives.

Extracting tar.gz File

Most Linux distributions and macOS comes with tar command pre-installed by default.

To extract a tar.gz file, use the --extract (-x) choice and specify the archive file title after the f choice:

$ tar -xf archive.tar.gz

The tar command will auto-detect compression kind and can extract the archive. The identical command can be utilized to extract tar archives compressed with different algorithms akin to .tar.bz2 .

If you’re a Desktop consumer and the command-line just isn’t your factor you need to use your File supervisor. To extract (unzip) a tar.gz file merely right-click on the file you need to extract and choose “Extract”. Home windows customers will want a device named 7zip to extract tar.gz information.

The -v choice will make the tar command extra seen and print the names of the information being extracted on the terminal.

$ tar -xvf archive.tar.gz

By default, tar will extract the archive contents within the present working listing . Use the --directory (-C) to extract archive information in a selected listing:

For instance, to extract the archive contents to the /house/linuxize/information listing, you need to use:

$ tar -xf archive.tar.gz -C /house/linuxize/information

Extracting Particular Recordsdata from a tar.gz File

To extract a selected file(s) from a tar.gz file, append a space-separated checklist of file names to be extracted after the archive title:

$ tar -xf archive.tar.gz file1 file2

When extracting information, you will need to present their precise names together with the trail, as printed by --list (-t).

Extracting a number of directories from an archive is identical as extracting information:

$ tar -xf archive.tar.gz dir1 dir2

If you happen to attempt to extract a file that doesn’t exist, an error message just like the next will likely be displayed:

$ tar -xf archive.tar.gz README
Output:
tar: README: Not present in archive
tar: Exiting with failure standing on account of earlier errors

You may as well extract information from a tar.gz file based mostly on a wildcard sample, through the use of the --wildcards choice and quoting the sample to stop the shell from decoding it.

For instance, to extract information whose names finish in .js (Javascript information), you’d use:

$ tar -xf archive.tar.gz --wildcards '*.js'

Extracting tar.gz File from stdin

If you’re extracting a compressed tar.gz file by studying the archive from stdin (normally via a pipe), that you must specify the decompression choice. The choice that tells tar to learn the archives via gzip is -z.

Within the following instance we’re downloading the Blender sources utilizing the wget command and pipe its output to the tar command:

$ wget -c https://obtain.blender.org/supply/blender-2.80.tar.gz -O - | sudo tar -xz

If you happen to don’t specify a decompression choice, tar will point out which choice it’s best to use:

Output:
tar: Archive is compressed. Use -z choice
tar: Error just isn't recoverable: exiting now

Itemizing tar.gz file

To checklist the content material of a tar.gz file, use the --list (-t) choice:

$ tar -tf archive.tar.gz

The output will look one thing like this:

file1
file2
file3

If you happen to add the --verbose (-v) choice, tar will print extra data, akin to proprietor, file dimension, timestamp ..and so forth:

$ tar -tvf archive.tar.gz
-rw-r--r-- linuxize/customers       0 2019-02-15 01:19 file1
-rw-r--r-- linuxize/customers       0 2019-02-15 01:19 file2
-rw-r--r-- linuxize/customers       0 2019-02-15 01:19 file3

Conclusion

tar.gz file is a Tar archive compressed with Gzip. To extract a tar.gz file, use the tar -xf command adopted by the archive title.

If in case you have any questions, please go away a remark under.

Related Posts

The 30 most useful Linux commands

This article will introduce some practical and common Linux or Unix command , which is the Linux system administrators normally use the command . This article is not a complete list, but a brief list of commands that can be useful...

15 Practical examples of tcpdump command

15 Practical examples of tcpdump command

The tcpdump is the most essential and powerful command-line network packet sniffing tool. We use it to analyze network packets, capture or filter TCP/IP packets that transferred and received over the network on a specific network interface. It is available in almost...

15 Useful “df” Commands to Check Disk Space in Linux

15 Useful “df” Commands to Check Disk Space in Linux

There are several Linux tools available on the internet to check disk space utilization; we can use any of them. But, Linux has a best built-in command-line utility called “df”. The “df” is the short form of “disk filesystem”, we can get detailed information on used...

15 Practical examples of echo command

15 Practical examples of echo command

If you are writing a bash script, you know echo command very well. It is use to display text lines on an output screen or a file. The echo command is the most common command used by all Linux users, and it is built-in Linux command. echo command syntax: echo...

Follow Us

Our Communities

More on Linux Command

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

one × 4 =

Shares