• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Extract (Unzip) Tar Gz File

Written by Admin, Updated On December 22, 2019
tar, terminal
How to Extract (Unzip) Tar Gz File

In this article, we will show you how to extract (or unzip) tar.gz and tgz archives.

Now a days in the open-source world .zip and .tar.gz files used on a regular basis. Most of Open-source packages are generally available to download in .tar.gz and .zip formats. A group of files converted into a archive using the tar command. You can compress as many formats such as gzip, bzip2, lzip, lzma, lzop, xz. Tar name derived from it’s real name “Tape ARchive”.

Gzip is the most popular algorithm for compressing tar files. By convention, the name of a tar archive compressed with gzip should end with either .tar.gz or .tgz. In simple, we can say a file that ends in .tar.gz is a .tar archive compressed with gzip.

The tar command is used for multi-purpose like to extract archive, display list of files, add file to existing archive and other operations.

Extract tar.gz File#

The tar command is pre-installed by default in most of Linux distributions and macOS. You can extract a tar.gz file using --extract (-x) operator followed by filename after f option:

tar -xf test_archive.tar.gz

The command will auto-detect the compress type and will extract the archive. You can use same command for other algorithms such as .tar.bz2.

If you are not familiar with command-line then you can use your File manager. Just simply-right click the file you want to extract (unzip) and select “Extract”. Windows users should have 7zip tool to extract tar.gz files.

If you would like to print the names of files which are being extracting on terminal then you can use the -v option with tar command.

tar -xvf test_archive.tar.gz

By default, tar will extract the archive contents in the current working directory. To extract archive files in a specific directory use the --directory (-C). For example, to extract the archive contents to the /home/sweta/data you have to use command as below:

tar -xf test_archive.tar.gz -C /home/sweta/data

Extract Specific Files from a tar.gz File#

Sometimes tar.gz files are big in size and need of any specific files instead of all from archive. Then you can use below command to extract a specific files. Pass space-separated list of file names which needs to be extract.

tar -xf test_archive.tar.gz file1 file2

Same as file you also can extract specific directories usign below command:

tar -xf test_archive.tar.gz dir1 dir2

Listing tar.gz file#

Use the --list (-t) option, to list the content of a tar.gz file:

tar -tf test_archive.tar.gz

It should show output as below:

file1
file2
file3

To print the files details such as owner, file size, timestamp, etc. pass the --verbose (-v) option:

tar -tvf test_archive.tar.gz
-rw-r--r-- sweta/users       0 2019-02-15 01:19 file1
-rw-r--r-- sweta/users       0 2019-02-15 01:19 file2
-rw-r--r-- sweta/users       0 2019-02-15 01:19 file3

Conclusion#

In this guide, we show you how to extract tar.gz file which is compressed with Gzip.

If you have any question or feedback, please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Git on Debian 10 Linux
Next Article   How to Install PostgreSQL on CentOS 8

Related Posts

  • How to Use sed to Find and Replace String in Files

    How to Use sed to Find and Replace String in Files

    December 18, 2020
  • Linux Head Command

    Linux Head Command

    December 16, 2020
  • Rename Files and Directories in Linux

    How to Rename Files and Directories in Linux

    December 15, 2020

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook