How To Extract .tar.gz Files using Linux Command Line

Posted at January 5, 2017 at 4:53 pm by Jithin

In this tutorial we can learn how to extract tar.gz files using Linux Command line tools.

A .tar.gz file is nothing, but an archive. It is a file that acts as a container for other files. The tar program provides the ability to create tar archives, as well as various other kinds of manipulation. For example, you can use Tar on previously created archives to extract files, to store additional files, or to update, or list files which were already stored. An archive can contain many files, folders, and subfolders, usually in compressed form using gzip or bzip2 program on Unix operating systems. Initially, tar archives were used to store files conveniently on magnetic tape. The name “Tar” comes from this use; it stands for tape archiver. You need to use the tar command which can create and manipulate archive files in .tar.gz under Unix like operating systems. It is very useful for archiving multiple files together into a single archive file. It allows us to restore files individually. Tar can direct its output to available devices, files, or other programs (using pipes), it can even access remote devices or files (as archives). tar.gz file is actually the product of two different things. Tar basically just packages a group of files into a single file bundle, but doesn’t offer compression on it’s own. To compress tar you’ll want to add the highly effective gzip compression. In this documentation, we can discuss about how to extract the tar.gz files from the command line. For this, open a command-line terminal and then type the following commands to open and extract a .tar.gz file.


Extracting .tar.gz files

1) If your tar file is compressed using a gzip compressor, use this command to uncompress it.

$ tar xvzf file.tar.gz


x: This option tells tar to extract the files.

v: The “v” stands for “verbose.” This option will list all of the files one by one in the archive.

z: The z option is very important and tells the tar command to uncompress the file (gzip).

f: This options tells tar that you are going to give it a file name to work with.

A tarball is a group or archive of files that are bundled together using the tar command and have the .tar file extension.


How To Extract .tar.gz Files using Linux Command Line


2)  To uncompress tar.gz file into a different directory, use the command below:

$ tar xvzf file.tar.gz -C /path/to/somedirectory

Where the -C argument is used to specify the path to place the file. By defaults files will be extracted into the current directory. To change the directory, we use -C option.


How To Extract .tar.gz Files using Linux Command Line



3) To extract test.doc file from the file.tar.gz tarball, use the following command:

$ tar -xvzf file.tar.gz test.doc


How To Extract .tar.gz Files using Linux Command Line


4) To view a detailed table of content by listing all files in archive, you can use the following command:

$ tar -tvf file.tar.gz


How To Extract .tar.gz Files using Linux Command Line


5) To extract the .gz file without tar, you can use the following command:

$ gunzip file.gz


How To Extract .tar.gz Files using Linux Command Line


Extracting .tar.bz2 files

This is just about the same as the gzip decompression. The major difference is that the z option has been replaced by the j option.

If your tar file is compressed using a bZip2 compressor, use the following command to extract it.

$ tar xvjf file.tar.bz2

Where ‘j’ will decompress a bzip2 file.


How To Extract .tar.gz Files using Linux Command Line


If you need any further assistance please contact our support department.



3.75 avg. rating (75% score) - 12 votes

You can skip to the end and leave a response. Pinging is currently not allowed.

6 Responses to “How To Extract .tar.gz Files using Linux Command Line”

  1. Faizan says:

    Nice explanation. Very helpful. Thanks a lot.

  2. ajwilcox says:

    Yes, very helpful for a Linux/Unix beginner, although a clearer distinction could have been made between extracting/unpacking, which lots of people want to do, and, on the other hand, compressing to .tar , which is a matter for professionals. ajw

  3. Mohammad says:

    Great explanation. Solved my issue in seconds. Thanks

  4. Saif says:

    Note that using gunzip myfile.gz will delete the source file. Use -k if you would like to keep this file.

  5. Brian says:

    I have a program that is in the tar.gz format. I did what you “said” but am unable to run the program. So what do I do to get the software running?

Leave a Reply