Jump to content

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


Recommended Posts



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


A lot 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 a very useful skill.


The name “Tar” stands for “Tape Archiver”, because when tar was invented it was used to place data on storage tapes. 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 just means to extract the contents of the tar file (also known as a tarball).


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.


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


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

How to Untar a tar.gz File

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


To untar tar.gz file enter the following:


tar xvzf file.tar.gz


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 Untar a tar.gz File to a Different Directory

To uncompress 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.


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


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



Edited by aum
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...