Untar Unzip or Extract Tar Files in Unix or Linux

How to extract tar files in Linux. Untar gz file in Linux. Many of the most popular downloadable Linux or Unix files found on the internet are compressed using a tar, tar.gz or .tgz compression format. So, knowing how to open or decompress these compressed files becomes very important.

Extract Tar gz, or Untar a Tar File in Linux or Unix

What is the Untar Command?

The untar command isn't a standalone command itself. However, you'll find that this term is often used to describe the process of extracting, unzipping or uncompressing tar gz files from a tar archive. The command we actually use for this purpose is called the tar command and is used in conjunction with specific extraction options or arguments which we cover next.

(Un)tar Command Options

Here is a breakdown of what each tar command option or argument does when this command is used to unzip tar, tar.gz, and tgz files:

Option What it does
-x Extract files from an archive.
-z Use gzip compression to extract the archive.
-v Be verbose, display the progress and file list.
-f Specifies the input file (e.g., .tgz file).
-C /myfolder Change to the specified directory before extracting files.

The following tar examples cover how to untar both popular formats and extract the contents of the compressed archive to a different directory.

How to Untar or tar unzip a "tar" file in Linux or Unix

You can unzip tar files in Linux or Unix by using the tar command along with the -xzvf options. Here's how:

  1. Open a terminal; ctrl+alt+t
  2. From the terminal, change to the directory where your .tar file has been downloaded.
    cd ~/directory_path
  3. To extract or tar unzip the file to the current directory, type the following command,
    (Making sure to replace file_name.tar with the actual filename)

    tar -xvf file_name.tar

    You can also specify a different directory to extract to using the -C parameter and path to the directory as follows:

    tar -C /myfolder -xvf file_name.tar

How to untar gz or extract a "tar.gz" file in Linux or Unix

To extract tar gz files in Linux or Unix from an open terminal:

  1. Change directory to where your .tar.gz file is located,
    cd ~/directory_path
  2. To extract the contents of the tar.gz file to the current directory,
    (replacing file_name.tar.gz with the actual name of your file), use the following command:

    tar -zxvf file_name.tar.gz

    Note that this process also works to decompress and extract the contents of a .tgz file:

    tar -xzvf file_name.tgz

    Or to extract to another directory, type the following, changing /myfolder to the path you want to extract to:

    tar -C /myfolder -zxvf file_name.tar.gz

There you have it. A few simple commands are all it takes to untar, unzip or extract tar gz files.

Hopefully this section has helped you decompress, unpack and extract those compressed tar and tar gz files you downloaded from the internet. If you are looking for additional helpful solutions, you might want to check out this How to Open Files as Root article.