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
.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
.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
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
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
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
--list (-t) option, to list the content of a
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
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.
Leave a Reply