+1 (506) 500-5957 sales@monovm.com Get US VPS for 50% OFF!

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.

Posted: 01 Jul, 21 Updated: 28 Oct, 23 by Antoniy Yushkevych 20 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 Windows and some useful tips and tricks.

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 in a more engaging way.

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

Stay tuned for the secrets of extracting these files. We'll also unveil the art of unzipping .tar.gz files on Linux, macOS, and Windows.

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 and macOS 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 own 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 own .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.

If you're a Windows user looking to untar tar.gz files, this section provides clear, user-friendly instructions for two popular tools: 7-Zip and WinRAR. Both tools offer a graphical user interface, making the extraction process straightforward.

Extracting .tar.gz Files Using 7-Zip

7-Zip is a free, open-source compression tool that supports a wide range of archive formats, including .tar.gz. Follow these step-by-step instructions to extract .tar.gz files using 7-Zip:

  1. Download and Install 7-Zip:

If you don't already have 7-Zip installed, you can download it from the official website here. Choose the version that matches your Windows system (32-bit or 64-bit) and follow the installation instructions.

  1. Locate the .tar.gz File:

Navigate to the directory where your .tar.gz file is located.

  1. Right-Click on the .tar.gz File:

Right-click on the .tar.gz file you want to extract.

  1. Select "7-Zip" from the Context Menu:

From the context menu that appears, hover over the "7-Zip" option.

  1. Choose "Extract Here" for Extraction:

In the submenu, select "Extract Here" to extract the contents of the .tar.gz file to the current directory.

  1. Extraction Progress:

7-Zip will begin extracting the files, and a progress window will appear. Once extraction is complete, you'll have access to the extracted files and folders in the same directory.

Untar tar.gz Files Using WinRAR

WinRAR is another popular file compression and extraction utility for Windows. Here's how to extract .tar.gz files using WinRAR:

  1. Download and Install WinRAR:

If you don't have WinRAR installed, you can download it from the official website here. Download the appropriate version for your Windows system (32-bit or 64-bit) and follow the installation instructions.

  1. Locate the .tar.gz File:

Navigate to the directory where your .tar.gz file is located.

  1. Right-Click on the .tar.gz File:

Right-click on the .tar.gz file you want to extract.

  1. Select "Extract Here" for Extraction:

From the context menu that appears, choose "Extract Here" to begin the extraction process.

  1. Extraction Progress:

WinRAR will extract the files, displaying a progress dialog. Once the extraction is finished, you can access the extracted files in the same directory.

Like Linux and macOS, the Windows 10 operating system also includes a built-in tar utility.

Unlike Windows' convenient graphical user interface (GUI) for unzipping .zip files, you must use the tar utility via the command line. However, you can install plenty of third-party tools for a more user-friendly experience.

Using the command line (cmd)

To access the Windows command line, search for "command prompt" or "cmd" in the search bar. Right-click on the first result and select the “Run as administrator” option.

Once the command prompt opens, use the appropriate commands to change the current working directory (cd) to the location of the .tar.gz file you want to unzip. Using the tar utility, You can specify a source and destination file path.

Type one of the following commands and press "Enter".

  • Extract the .tar.gz file to the current working directory:

tar -xvzf filename.tar.gz

  • Extract .tar.gz file from source path to destination path:

tar -xvzf C:\PATH\TO\SOURCE\filename.tar.gz -C C:\PATH\TO\DESTINATION

Note that the tar utility on Windows has almost the same syntax as on Linux and macOS. Here we used the extract (-x), verbose (-v), decompress with gzip (-z), and file (-f) options for a full extraction with decompression and verbose output.

Use of third-party tools

If the command line isn't your thing, there are plenty of user-friendly tools to unzip tar.gz files. Although there are many tools to choose from, the most popular are 7-Zip and WinZip. Although slightly different, they are quite lightweight and provide a much easier alternative to using the command line.

Some third-party tools also offer extended flexibility for converting between file types, saving time if you want to change compression formats. Many are also available for Linux and macOS.

However, while tools like 7-Zip are free, many more "robust" solutions are only available for a price after a trial period. Therefore, we recommend using the free (but trustworthy) tools or just the command line.

Extract tar files from a .tar.gz file

To extract an archive, right-click on its file (which will be in . tar or . tar. gz), then choose "Extract archive" (or equivalent wording depending on your Ubuntu variant, such as "Unzip archive").

Extract tar files from a .tar.gz file from stdin

You can also extract the .tar.gz directly from the standard input stream (stdin) by putting it into the tar command using the unzip option ( -z ). 

Listing tar.gz files

tar List the contents of a (compressed) archive: tar -tf archive name. tar(.gz) Unzip an archive: gzip -d archive name. tar Unlink an archive: tar -xvf archive.

On MacOS, you can easily extract a .tar.gz file using the built-in Terminal application and the "tar" command. Follow these steps:

  1. Open the Terminal application. You can find it in the Utilities folder within the Applications directory.
  2. Navigate to the directory where the .tar.gz file is located. For instance, if the file is on your Desktop, you can use the following command to navigate there:

cd ~/Desktop

  1. To extract the .tar.gz file, use the following command:

tar -xzvf mywebsitebackup.tar.gz

This command will extract the contents of the .tar.gz file into the current directory.

  1. If you prefer to extract the contents to a specific directory, use the following syntax:

tar -xzvf mywebsitebackup.tar.gz -C /path/to/directory

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

Now you've successfully extracted the contents of the .tar.gz file on your macOS system.

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:

  1. 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.

  1. 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.

Untar tar.gz Files from stdin on Windows

On Windows, you can employ similar techniques to extract .tar.gz files from stdin, but the process may involve using third-party tools like Git Bash, Cygwin, or Windows Subsystem for Linux (WSL). Here's an example using Git Bash:

  1. Download the .tar.gz File: Using a tool like wget or curl, untar tar.gz file. For example:

curl -L https://example.com/archive.tar.gz | tar -xz

In this command, -L is used with curl to follow redirects if the URL redirects to another location.

  1. Extract to a Specific Directory (Optional): To specify an extraction directory, adjust the tar command accordingly:

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

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

Please note that these examples assume you have the necessary tools installed on your Windows system. Depending on your setup, you may need to adapt the commands or use different tools to achieve the same result.

To untar tar.gz files from stdin offers flexibility when dealing with data pipelines and remote archives, enabling you to efficiently process and extract data without the need for temporary files or manual downloads.

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. 

People are also reading:

Frequently Asked Questions

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