How to Extract Tar Gz File in Linux - [Untar tar.gz]

This blog post will help you to get information about how to unzip tar.gz file, untar tar.gz file, and extract tar GZ file in Linux? Also, you can get a detailed guide to executing the overall process.

Updated: 01 May, 24 by Antoniy Yushkevych 12 Min

List of content you will read in this article:

Many files are compressed and stored from videos to entire software using the .tar.gz format. Although extracting a .tar.gz file is not as easy as unzipping a .zip, it is still quite simple. As software becomes more powerful and media becomes more data-rich, file sizes continue to grow exponentially. Therefore, it is increasingly common to store and send files in compressed formats such as .tar.gz. However, compressing and extracting these files is not always intuitive. This guide will provide basic instructions for unzipping .tar.gz files on Linux and some useful tips and tricks.

📄 Need a quick reference? Check out our comprehensive Linux Commands Cheat Sheet for all the essentials!

A “.tar” file is a collection of files compressed into a single file or archive. Short for “Tape ARchive,” the name “TAR” is a throwback to when files were stored on magnetic tape drives. Luckily, you don't have to be a 1960s computer geek to use and extract .tar files – and modern .tar files aren't even like old computers.

Much like more familiar .zip files, .tar files compress large files into a single package, making them easier to store and send via email, servers, and more. As a result, it has become a common file extension for many free software and other resources.

But if .zip is the easiest to use, why use .tar in the first place? As we will see in the next section, .tar has a few additional characteristics that make it the best compression format for certain files and applications.

TAR is an abbreviation for Tape ARchive. This command was primarily developed to create archives and store the files on magnetic tape. Hence, the name Tape Archive. 

The tar command helps you to generate several tar archives as it converts as many files as you want into archives. When we talk about the tar command, it can be used in ample ways. You can use it to add files to the archive, delete files, or extract tar archives. The list is pretty long.

Being a techie, it is highly evident that you are already familiar with the .tar.gz files. These files are commonly known as ‘tarballs’. They are used by Linux, macOS, or even Windows users for backups or data archival. Now, there are various methods to compress tar files. One of the most used methods to compress a file is Gzip. Moreover, whenever you compress the tar archive with gzip, it ends with .tar.gz or .tgz extension. 

Besides, if you are a Windows user, you may need to download the 7zip tool to extract tar.gz file in Linux. A lot of such third-party applications are also available in the market. They do come with a drawback: they do not work every time. In this article, we will familiarise you with some ways to unzip/untar/extract tar.gz archives in both Linux and Windows. 

Compressed file formats like .tar.gz offer several advantages that make them a popular choice for various purposes. Understanding these advantages can help you make informed decisions when dealing with file compression and archiving. Here are some key benefits:

  1. Efficient Compression: .tar.gz files use the GZIP compression algorithm, which is known for its excellent compression capabilities. It efficiently reduces the size of files and directories, making it easier to store and transfer large volumes of data.
  2. File Integrity: When you compress files into a .tar.gz archive, the format includes checksums that ensure the integrity of the archived data. This means that you can verify the contents of the archive to ensure that no data corruption has occurred during storage or transfer.
  3. Cross-Platform Compatibility: One of the significant advantages of .tar.gz files is their compatibility with multiple operating systems. Whether you're using Linux, Windows, macOS, or other Unix-like systems, you can extract and create .tar.gz archives without compatibility issues.
  4. Preserves File Attributes: When you create a .tar.gz archive, it preserves file attributes such as permissions, ownership, and timestamps. This feature is crucial when archiving files with specific permissions or metadata that need to be retained.
  5. File Grouping: A .tar.gz archive allows you to bundle multiple files and directories into a single package. This grouping simplifies organization and management, especially when dealing with related files or project backups.
  6. Incremental Backups: For data backup purposes, .tar.gz archives can be used for incremental backups. This means that you can update an existing archive by adding or replacing only the files that have changed, reducing storage and transfer requirements.
  7. Open-Source Tools: Numerous open-source and freely available tools support .tar.gz compression and extraction. This accessibility makes it easy for users to work with .tar.gz files without incurring additional costs.

In the world of file compression, .tar, and .tar.gz files may seem like enigmatic codes. Let's decode the differences more engagingly.

.tar Files: These are collections of uncompressed files, affectionately known as "tarballs." To compress them, you'll need a sidekick—gzip. Together, they create .tar.gz files.

On the other hand, .zip Files are like a magician's hat; each file is pre-compressed. No extra steps are required.

Choosing between them is like choosing between convenience and space efficiency. .zip files are easy to access but less space-savvy, while .tar files save space but demand a bit more effort. Keep in mind, .tar.gz files are essentially .tar files wrapped in a gzip hug. There are other compression techniques like .tar.bz2, .tar.br, and .tar.zst.

After mastering the 🗜️ Zip Command in Linux, you might want to know how to reverse the process. Check out our detailed guide on 📂 Linux Unzip to easily access your files!"

It is a simple process to extract tar.gz file in Linux. Before that, take a look at the meaning of these symbols:

1. x: This option is used to extract the files.

2. v: It means Verbose. It helps to list the files in the archive. 

3. z: This is used to uncompress a file.

4. f: Using this option, you can easily keep a name for the file.

Most Linux distributions include built-in tools to compress and decompress .tar and .tar.gz files. Although the tar utility is sufficient for most purposes, you will need the gzip utility to create .tar.gz files.

Decompressing .tar.gz files on Linux

You can decompress most .tar.gz and other compressed .tar files using the tar utility. For the easiest method, start by opening the terminal (CTRL+ALT+T) and navigating to the directory of the .tar.gz file you want to unzip. Then enter the following command:

tar -xf filename.tar.gz

This command extracts (-x) the specified (-f) file (in this case, filename.tar.gz) to the current directory. Note that this command also works with other common compression formats such as .tar.bz2.

The tar command also has several other options. Like many Linux commands, one is a verbose output (-v) that displays the extracted files in the terminal window. To extract the .tar.gz file to the current working directory and print the output:

tar -xvf filename.tar.gz

Again, the above commands will extract the current working directory by default. You can use the -C option to extract to a different directory (in this case, /home/user/files). To extract the .tar.gz file to another working directory:

tar -xf filename.tar.gz -C /home/user/files

The tar command extracts only specific files or directories from a .tar.gz file. Just add a list, separated by spaces, of the files you want to extract.

To extract the file1 and directory1 from the .tar.gz file into the current working directory:

tar -xf filename.tar.gz file1 directory1

You can also extract the .tar.gz file directly from the standard input stream (stdin) by placing it in the tar command using the unzip (-z) option. For example, if you want to extract the .tar.gz file located at "https://kinsta.com/filename.tar.gz" (there isn't actually a .tar.gz file here, but bear with us), you will use the wget command introduced in tar.

To extract the .tar.gz file from a URL:

wget -c https://kinsta.com/filename.tar.gz -O - | sudo tar -xz

It is often useful to list the contents of a .tar.gz file without having to unpack the entire archive. The -list (-t) option returns a list of filenames.

To list the contents of a .tar.gz file:

tar -tf filename.tar.gz

You can also add the verbose (-v) output option to provide detailed listings, including dates, titles/permissions, and more.

To list the detailed content of a .tar.gz file:

tar -tvf filename.tar.gz

Many compression utilities also provide their commands for listing the contents of compressed files. For example, gzip allows you to list the contents of a .gz file with the following command:

To list the detailed contents of a .gz file with gzip:

gzip -l filename

You can create your .tar files compressed using compression utilities such as gzip. Gzip is one of the most popular and widely available options, especially because it's built into most Linux and macOS distributions.

In the terminal, navigate to the working directory of the .tar file you wish to compress and enter the following command:

gzip filename.tar

You can just as easily decompress the resulting .tar.gz file with the decompress (-d) option.

gzip -d filename.tar

If you want to keep the original file after compression, there are two options. One is the -k option, and the other uses the -c option to output the compressed file to a different file, preserving the original.

gzip -c filename.tar

🐧💻 Harness the power of Linux VPS hosting and take control of your online presence with unmatched performance and flexibility! 🚀🌐 Supercharge your website with dedicated resources and seamless scalability for ultimate success.

In certain scenarios, you may encounter .tar.gz files that need to be extracted directly from the standard input stream, commonly referred to as stdin. This situation often arises when dealing with data sources that provide archives through pipelines or web downloads. Fortunately, you can efficiently untar tar.gz files from stdin using the appropriate command-line tools.

Untar tar.gz Files from stdin on Linux and Unix-like Systems

To extract a .tar.gz file from stdin on Linux and Unix-like systems, you'll typically use a combination of the wget or curl command to retrieve the archive and then pipe it into the tar command for extraction.

Here's a step-by-step process:

  • Download the .tar.gz File: Use a command-line tool like wget or curl to fetch the .tar.gz file. For instance:

wget -O - https://example.com/archive.tar.gz | tar -xz

In this command, -O - instructs wget to output the downloaded content to stdout, which is then piped (|) into tar for extraction. The -xz options for tar indicate that it should extract (-x) and decompress (-z) the data.

  • Extract to a Specific Directory (Optional): If you want to extract the contents to a specific directory, you can specify the destination using the -C option with tar. For example:

wget -O - https://example.com/archive.tar.gz | tar -xz -C /path/to/destination

Replace /path/to/destination with the desired directory path.

By utilizing this method, you can efficiently untar tar.gz files from stdin, making it a convenient approach for automation, scripting, or when working with data streams.

In a nutshell, tar.gz files or tarballs archive data and backups. It is necessary to decompress and extract these files to get your work going. There are specific ways and methods to conclude your task through various steps and commands. 

As you have seen, this article assists you in extracting the tar.gz file [unzip tar.gz file, untar tar.gz file], whether you are a user of  Linux or Windows. We hope that the information provided in this article helps you in the best possible way. 

While all tar.gz files are .tar history saved files, not all .gz are .tar files. The .gz extension represents the gzip compact format that can use to almost any file format to compress data and save space.

GZ file is a sort of a tarball compact with the gzip algorithm. TAR is the extension of tarballs, instead of GZ denotes gzip. The TGZ file extension is still used sometimes whereas of TAR. GZ. Bzip2: Similar to gzip, several other file compactness algorithms are available as well, like bzip2.

Once using Windows, you will extract GZ files by the "tar" command in Command Prompt or through installing the 7-Zip program. Once on a Mac, solely go for a double-click the file to extract it, or use the command gunzip filename. gz in a Terminal window. Once using Linux, use the gzip -d file name.

Tar GZ files are frequently used for: 1. Storing multiple files in one storage. 2. Sending and receiving larger files through a compressed format. 3. Compacting single files to store locally.

Yes. Since .tar.gz compresses multiple files at the same time, it can take advantage of similarities between individual files to save space. Generally, a collection of files archived and compressed as .tar.gz will be more space efficient (i.e., smaller) than the same collection compressed as .zip.

Antoniy Yushkevych

Antoniy Yushkevych

Master of word when it comes to technology, internet and privacy. I'm also your usual guy that always aims for the best result and takes a skateboard to work. If you need me, you will find me at the office's Counter-Strike championships on Fridays or at a.yushkevych@monovm.com