How to Extract tar.gz File in Linux by Using the Command Line

This article will learn how to extract/untar tar.gz files in Linux systems through the command line using the tar command.

Many of the downloadable Linux/Unix files found on the internet are compressed using a tar.gz format. Therefore, knowing how to open or untar tar.gz files is very useful.

The name “Tar” stands for “Tape Archiver” because it was used to place data on storage tapes when tar was invented. A .tar.gz file is nothing but an archive. The tar program takes one or more files and “wraps” them into a self-contained file.

To untar tar.gz files means to extract the contents of the tar file (also known as a tarball). Additionally, if you want to learn how to create tar.gz files in Linux, check out our excellent guide, “How to Create tar.gz Archive Using the tar Command on Linux.”

People new to the .tar format usually equate it to a .zip archive, but a tar archive is not compressed. Tar collected all the files into one package, but the files can be compressed with separate utilities.

The most often used algorithm for compressing tar files is Gzip. By convention, the name of a tar archive compressed with gzip becomes .tar.gz or .tgz.

To put it simply: a file that ends in .tar.gz is just a .tar archive compressed with gzip.

How to Extract a tar.gz File

Most Linux distributions come with the tar command pre-installed by default.

To untar tar.gz file, enter the following:

tar xvzf file.tar.gzCode language: CSS (css)

Let’s break down this syntax. Here is what each parameter in that command means:

  • x: This option tells tar to extract the files.
  • v: Verbose output shows you all the files being extracted.
  • z: Tells tar to decompress the archive using gzip.
  • f: This must be the last flag of the command. It tells tar the name and path of the compressed file.

How to Extract a tar.gz File to a Different Directory

To uncompress the tar.gz file and put resulted files in a different directory, say /tmp/archive, you need to add a -C option at the end of the command:

tar xvzf file.tar.gz -C /tmp/archive

The -C option is used to specify a different directory other than the current working directory.

View a List of Files within an Archive

Sometimes you need to view the content of a tar file as it collects many files and ensures if a specific file is present. 

To view a detailed table of contents for archive called data.tar.gz, use the following syntax:

tar tf data.tar.gzCode language: CSS (css)
View a List of Files within tar.gz Archive


  • t: Used to list the content of the tar file
  • f: Commanding the utility to use the file mentioned in the following argument

You can also get detailed standard output by using the v (verbose) option.

tar tvf data.tar.gzCode language: CSS (css)
How to Extract tar.gz File in Linux by Using the Command Line


Now you know how to untar a tar.gz file in Linux. Perhaps you might also be interested in learning how to unzip files in Linux.

For more about tar command in Linux, consult its manual page.

If you find this article helpful or have additional ideas, please use the comment box below.

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Think You're an Ubuntu Expert? Let's Find Out!

Put your knowledge to the test in our lightning-fast Ubuntu quiz!
Ten questions to challenge yourself to see if you're a Linux legend or just a penguin in the making.

1 / 10

Ubuntu is an ancient African word that means:

2 / 10

Who is the Ubuntu's founder?

3 / 10

What year was the first official Ubuntu release?

4 / 10

What does the Ubuntu logo symbolize?

5 / 10

What package format does Ubuntu use for installing software?

6 / 10

When are Ubuntu's LTS versions released?

7 / 10

What is Unity?

8 / 10

What are Ubuntu versions named after?

9 / 10

What's Ubuntu Core?

10 / 10

Which Ubuntu version is Snap introduced?

The average score is 68%