From videos to entire software packages, many files are compressed and stored using the .tar.gz format. While extracting a .tar.gz file isn’t quite as easy as unzipping a .zip, it’s still pretty straightforward.
As software becomes more powerful and media becomes more data-rich, file sizes continue to grow at exponential rates. As a result, it’s becoming increasingly common to store and send files in compressed formats as .tar.gz.
Compressing and extracting these files, however, isn’t always intuitive. In this guide, we’ll provide basic guides to unzip .tar.gz files in Linux and Windows, as well as a few helpful tips and tricks.
What Are .tar and .tar.gz Files?
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.
Thankfully, you don’t need to be a 1960s computer technician to use and extract .tar files – nor do modern .tar files even have anything to do with old computers.
Just like the more familiar .zip files, .tar files compress large files into a single package, making it easier to store and send them through email, servers, and so on. As a result, it’s become a common file extension for many open-source software packages and other resources.
But with .zip being the easier of the two to use, why use .tar in the first place? As we’ll see in the next section, .tar comes with a few extra features that make it the better compression format for certain files and applications.
.tar vs .zip
Where most operating systems make it easy to extract and create .zip files, the same can’t really be said for .tar files — at least not in ways that are easy to notice.
Of course, that’s not to say .tar files are some kind of “lesser” format than .zip. Rather, they both accomplish the same task (file compression) in the same way. Here’s a breakdown of how it all works.
- A .tar file is a collection of uncompressed files, sometimes known as a tarball. Since .tar doesn’t compress anything, it requires a separate compression utility for compression. As we’ll see later, one popular compression utility is gzip, which compresses a .tar into a .tar.gz file.
- A .zip file is a collection of compressed files. Rather than use a separate compression utility to compress the entire collection, .zip automatically compresses each file within the collection.
By now, you’ve probably noticed the major difference between .tar and .zip files: compression methods.
Where .zip files consist of many individually compressed files, .tar files are compressed as a single package, leaving its files uncompressed. In other words, .zip files are a collection of compressed files, while .tar files are a compressed collection of files.
But does the compression method really matter, especially if both methods technically produce compressed files?
It depends. For sending and storing, both .zip and .tar.gz files will allow you to send relatively large packages as a single file. However, there are some pretty major differences when it comes to accessing data within the files and the compression efficiency.
- .zip files are more accessible. Since data in a .zip are compressed individually, they can also be accessed individually. By contrast, data in a .tar.gz is only accessible after extracting the entire file.
- .tar.gz files are more space-efficient. Since .tar files are compressed as a single entity rather than a group of individually compressed files, compression utilities can group similarities between files and cut down on space. In other words, compressing files as a single group allows for more efficient compression methods, thereby saving space and reducing the overall size of the file.
If that’s not entirely clear, don’t worry. Technical details aside, all you need to remember is that .zip files are more accessible but less space-efficient, while .tar files are less accessible but more space-efficient. As a result, one isn’t necessarily better than the other — it’s all a matter of application.
What’s The Difference Between .tar and .tar.gz Files?
While both .tar and .tar.gz refer to file archives, a .tar.gz file is a .tar file that’s been compressed or “zipped” using the gzip utility. Using gzip for compression is what gives the file a “.gz” double extension.
Though gzip is the most common compression utility, it’s not the only one. As you might imagine, using a different compression utility on a .tar file will result in a different double extension. Some common examples include .tar.bz2 (bzip2), .tar.br (Brotli), and .tar.zst (zstd), among many others.
As we’ll see later, different compression utilities may require different methods for extracting and unzipping files. Though we’ll mostly focus on .tar.gz files, check out the end of the article for some quick tips on extracting .tar files in other formats.
Otherwise, keep reading to learn how to unzip .tar.gz files in Linux, macOS, and Windows.
How Do I Unzip a .tar.gz File in Linux Terminal?
Most Linux distributions and macOS include built-in tools for zipping and unzipping .tar and .tar.gz files. While the
tar utility is enough for most purposes, you’ll need the
gzip utility to create .tar.gz files.
Unzip .tar.gz in Linux
You can unzip most .tar.gz and other compressed .tar files using the
For the simplest method, begin by opening the terminal (CTRL+ALT+T) and navigate to the directory of the .tar.gz file you want to unzip. Then enter the following command:
Extract .tar.gz file to current working directory:
tar -xf filename.tar.gz
This command will extract (
-x) the file (
-f) specified (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.
tar command also comes with several other options. Like many Linux commands, one of these is a verbose output (
-v) that prints the extracted files to the terminal window:
Extract .tar.gz file to current working directory and print output:
tar -xvf filename.tar.gz
Again, the above commands will extract to the current working directory by default. You can use the
-C option to extract to a different directory (in this case, /home/user/files).
Extract .tar.gz file to a different working directory:
tar -xf filename.tar.gz -C /home/user/files
Only Extract Specific Files or Directories From .tar.gz in Linux
tar command also provides support for extracting only specific files or directories from a .tar.gz file. Simply add a space-separated list of the files you want to extract.
Extract file1 and directory1 from .tar.gz file to current working directory:
tar -xf filename.tar.gz file1 directory1
Note that this command will throw an error unless you specify the exact filename listed in the .tar file. As we’ll cover more in the next section, you can verify file names by listing contents with the
tar -tf filename.tar.gz command.
You can also use
--wildcards to extract all files with a certain extension or name.
Extract all files ending with “.txt” from .tar.gz file:
tar -xf filename.tar.gz --wildcards '*.txt'
Unzip .tar.gz From stdin in Linux
You can also extract .tar.gz directly from the standard input stream (stdin) by piping it into the
tar command using the decompression option (
For example, if you wanted to extract the .tar.gz file located at “https://kinsta.com/filename.tar.gz” (there’s not actually a .tar.gz file here, but bear with us), you’d use the
wget command piped into
Extract .tar.gz file from a URL:
wget -c https://kinsta.com/filename.tar.gz -O - | sudo tar -xz
List Contents of .tar.gz File in Linux
It’s often useful to list the contents of a .tar.gz file without having to unzip the entire archive. The
-t) option will output a list of filenames.
List contents of a .tar.gz file:
tar -tf filename.tar.gz
You can also add the verbose output option (
-v) to provide detailed listings, including dates, securities/permissions, and more.
List detailed contents of a .tar.gz file:
tar -tvf filename.tar.gz
Many compression utilities also offer 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:
List detailed contents of a .gz file with gzip:
gzip -l filename
Zip and Unzip .tar and .tar.gz in Linux with gzip
You can create your own compressed .tar files using compression utilities such as
gzip. Gzip is one of the most popular and available options, especially since it comes built in to most Linux distributions and macOS.
In the terminal, navigate to the working directory of the .tar file you want to compress and simply enter the following command:
Compress .tar file with gzip:
You can just as easily unzip the resulting .tar.gz file with the decompress (
Decompress .tar.gz file with gzip:
gzip -d filename.tar
If you want to keep the original file after compression, there are two options. The first is the
-k option, and the other uses the
-c option to output the compressed file to a different file, preserving the original.
Compress .tar file and keep original copy:
gzip -c filename.tar
Compress .tar file and store as a different file:
gzip -c filename.tar > newfilename.tar.gz
gzip also allows you to zip and unzip multiple files or entire directories at a time.
Compress multiple files:
gzip file1 file2
Decompress multiple files:
gzip -d file1 file2
Compress all files in a directory:
gzip -r directory1
Decompress all files in a directory:
gzip -dr directory1
How Do I Unzip a .tar.gz File in Windows 10?
Like Linux and macOS, the Windows 10 operating system also includes a built-in
Unlike Windows’ convenient graphical user interface (GUI) for unzipping .zip files, you’ll need to use the
tar utility through the command line. However, there are also many third-party tools you can install 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 the first result and select the “Run as administrator” option.
With the command prompt open, use the appropriate commands to change the current working directory (
cd) to the location of the .tar.gz file you want to unzip. Alternatively, you can also specify a source and destination file path when using the
Type one of the following commands and press “Enter.”
Extract .tar.gz file to 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 in Windows has nearly the same syntax as it does in Linux and macOS. Here we’ve used the extract (
-x), verbose (
-v), decompress with gzip (
-z), and file (
-f) options for a complete extraction with decompression and detailed output.
Using Third-Party Tools
If the command line isn’t your thing, there are plenty of user-friendly tools available to unzip tar.gz files.
While there are many tools to choose from, the most popular include 7-Zip and WinZip. While slightly different, they are quite lightweight and offer a much simpler alternative to using the command line.
Some third-party tools also offer extended flexibility for converting between file types, saving more time if you want to change between 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. As a result, we recommend sticking to free (but trustworthy) tools or simply using the command line.
Troubleshooting Common Errors
Not every .tar.gz extraction is seamless — especially if you’re using the command line!
Where commands have little (if any) room for typos or omissions, many common errors are the result of small mistakes, misspellings, or incorrect formats. Thankfully, unless you’re somehow missing your
gzip utility, most common errors are very easy to fix.
tar: README: Not found in archive
This error occurs when trying to extract specific files or directories from a .tar.gz file using
tar -xf filename.tar.gz FILE
tar: FILE: Not found in filename tar: Exiting with failure status due to previous errors
In this example, the user tried to extract the file titled “FILE” from filename.tar.gz. However,
tar was unable to find FILE within .tar.gz, meaning that the user either misspelled the name or that the file simply doesn’t exist in filename.tar.gz. Another common cause of errors is case sensitivity, where Linux treats “FILE” and “file” as two separate entities.
Solution: Check the spelling and/or verify that the file exists in the .tar.gz archive by listing the contents with
tar -tf filename.tar.gz.
tar: Archive is compressed. Use -z option
This error occurs if you try to decompress a file without specifying a decompression utility, specifically
wget -c https://kinsta.com/filename.tar.gz -O - | sudo tar -x
Notice that the “
-z” is missing from what should be
sudo tar -xz on the far right.
tar: Archive is compressed. Use -z option tar: Error is not recoverable: exiting now
Solution: Specify a decompression option such as
-z) in the
gzip: stdin: not in gzip format
Many users report running the “right” commands only to find that their .tar.gz is “not in gzip format” – despite the .gz extension.
gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error exit delayed from previous errors
This error usually occurs when a .tar has been saved as a .gz despite having never been compressed using the gzip utility. It may sound like a silly mistake, but it’s surprisingly common in situations where users directly rename files and their extensions (such as .tar and .gz) in the process.
Solution: Find a new copy of the .tar.gz file, or simply extract it as a .tar file using
tar -xf filename.tar instead. If this command also throws an error, the next solution might help.
tar: Unrecognized archive format
Similar to the previous error, this error occurs when an archive was saved as a .tar despite not being a .tar archive.
tar: Unrecognized archive format tar: Error exit delayed from previous errors.
Solution: Find a new copy of the .tar or .tar.gz file, or try extracting with
filename.tar.gz instead. If the gunzip command doesn’t work, try listing the contents with verbose output with
tar -xvf filename.tar.gz and see if there’s a specific file causing the problem. However, it’s more likely that the file was never properly zipped as a .tar file in the first place.
It’s easy to get confused when navigating between .tar, .tar.gz, and .gz – not to mention zipping and unzipping them. Here are a few frequently asked questions we commonly hear from users working with .tar.gz files.
How Do I Open A .tar.gz File?
You can open most .tar.gz files using the
tar command built in to Linux, macOS, and Windows 10. If you’re not comfortable with the terminal or command line, third-party tools such as 7-Zip offer a more user-friendly alternative.
Is .gz a .tar File?
While every tar.gz file is a .tar archive, not every .gz is a .tar file. The .gz extension represents the gzip compression format, which can be applied to almost any file format to compress data and save space.
Is .tar.gz The Same As .zip?
Though both .zip and .tar.gz archive and compress files, they do so in different ways. Where .zip archives and compresses individual files, .tar only archives individual files, leaving a separate compression format such as .gz (gzip) to compress all of them as a single file/archive. In other words, .zip is a collection of compressed files, while .tar.gz is a compressed collection of files.
Is .tar.gz More Efficient Than .zip?
Yes. Since .tar.gz compresses multiple files all at once, it can take advantage of similarities between individual files to save on space. Generally speaking, a collection of files archived and compressed as a .tar.gz will be more space-efficient (i.e., smaller) than the same collection compressed as a .zip.
With Linux, macOS, and Windows 10 offering a built-in tar utility, it’s easier than ever to unzip tar.gz files through the command line. Usually, the only command you’ll really need is:
tar -xvzf filename.tar.gz
Like many archive and compression formats, .tar.gz is an effective way to save storage space and make it easier to send large amounts of data. If you plan to distribute and store .tar.gz files on your website, Kinsta’s managed hosting services can help make the most of your space.
For more information and to schedule a live demo, contact a hosting expert from Kinsta today.