How to untar gzip file in linux?
- Open the terminal application.
- For remote systems use the ssh command for log in purposes.
- To decompress .gz files, use: gzip -d filename.gz.
- One can unzip and open gz file using: gunzip archive.gz.
- For .tar.gz/.tgz file try the tar command: .
- Run the ls command to list the files.
Many 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 very useful.
The name “Tar” stands for “Tape Archiver” because it was used to place data on storage tapes when tar was invented. 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 means to extract the contents of the tar file (also known as a tarball). Additionally, if you want to learn how to create tar.gz files in Linux, check out our excellent guide, “How to Create tar.gz Archive Using the tar Command on Linux.”
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.
The most often used algorithm for compressing tar files is Gzip. By convention, the name of a tar archive compressed with gzip becomes .tar.gz or .tgz.
To put it simply: a file that ends in .tar.gz is just a .tar archive compressed with gzip.
Most Linux distributions come with the tar command pre-installed by default.
To untar tar.gz file, enter the following:
Let’s break down this syntax. Here is what each parameter in that command means:
To uncompress the 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:
The -C option is used to specify a different directory other than the current working directory.
Sometimes you need to view the content of a tar file as it collects many files and ensures if a specific file is present.
To view a detailed table of contents for archive called data.tar.gz, use the following syntax:
Where:
You can also get detailed standard output by using the v (verbose) option.
List of content you will read in this article:
TAR is an abbreviation for Tape ARchive. This command was primarily developed to fulfill the purpose of creating archives and storing 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, that is, they do not work every time.
In this article, we are going to make you familiar with some ways to unzip/untar/extract tar.gz archives in both Linux and Windows.
Let’s begin!
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: You can easily keep a name for the file by using this option.
To start with, if the file is compressed by a gzip compressor, you can apply the following command:
tar -xzf filename.tar.gz
In this command, filename.tar.gz is the name of the archive that you want to unpack tar.gz file. Additionally, if you want to seek more information about the files, you may use the -v option. Here, -v stands for Verbose. Take a look:
tar -xvzf filename.tar.gz
Easy, right? But somehow if your work impedes and you don’t get the desired results, follow another method.
Follow the below-given procedure to unzip .ta.gz file without gzip command.
tar -xf filename.tar.gz
And your work is done.
$ tar xvzf file.tar.gz -C /path/to/somedirectory
Here, -C is used to mention the particular path to store the file.
$ tar -xvzf file.tar.gz test.doc
tar -xf archive.tar.gz file1 file2
tar -xf archive.tar.gz dir1 dir2
Simple, right?
tar -xvf archive.tar.gz
Sometimes you get an error message like this:
tar -xf archive.tar.gz README
It implies that the files that you want to extract don't exist.
tar -tf archive.tar.gz
Here is the output.
file1
file2
file3
Well, these were some of the commands to extract tar.gz files in Linux.
The next segment talks to you about extracting tar.gz files in Windows. Let’s see how!
If you are a Windows user, here are a few steps for you to follow so that you can easily extract/untar tar gz file.
.tar.gz files.
Step 1. Tap on Start on your Windows
Step 2. Now, go to the Command Prompt and click right. Choose Run as Administrator option
Step 3. Enter this command in the command prompt: tar -xvzf C:\PATH\TO\FILE\FILE-NAME.tar.gz -C C:\PATH\TO\FOLDER\EXTRACTION
You can add any desired path to store your files. After you press enter, all the files will be extracted to the path that you mention.
If you do not wish to use the command line method, don’t worry. There is another solution. You can simply head towards the File manager and click right on the file that you wish to extract. Choose the Extract option.
That’s it. You are done.
In a nutshell, tar.gz files or tarballs are used to archive data and backups. It is necessary to decompress and extract these files in order 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 to extract 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.
Keep learning. Keep evolving.
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.
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.
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.
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.
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.
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.
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.
You can unzip most .tar.gz and other compressed .tar files using the tar utility.
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:
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.
The 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:
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:
The 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:
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:
You can also extract .tar.gz directly from the standard input stream (stdin) by piping it into the tar command using the decompression option (-z).
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 tar.
Extract .tar.gz file from a URL:
It’s often useful to list the contents of a .tar.gz file without having to unzip the entire archive. The -list (-t) option will output a list of filenames.
List contents of a .tar.gz file:
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:
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:
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 (-d) option.
Decompress .tar.gz file with gzip:
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:
Compress .tar file and store as a different file:
Like the tar utility, gzip also allows you to zip and unzip multiple files or entire directories at a time.
Compress multiple files:
Decompress multiple files:
Compress all files in a directory:
Decompress all files in a 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’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.
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 tar utility.
Type one of the following commands and press “Enter.”
Extract .tar.gz file to current working directory:
Extract .tar.gz file from source path to destination path:
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.
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.
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 tar or gzip utility, most common errors are very easy to fix.
This error occurs when trying to extract specific files or directories from a .tar.gz file using tar.
Error Input:
Error Output:
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.
This error occurs if you try to decompress a file without specifying a decompression utility, specifically -z for gzip.
Error Input:
Notice that the “-z” is missing from what should be sudo tar -xz on the far right.
Error Output:
Solution: Specify a decompression option such as gzip (-z) in the tar command.
Many users report running the “right” commands only to find that their .tar.gz is “not in gzip format” – despite the .gz extension.
Error Output:
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.
Similar to the previous error, this error occurs when an archive was saved as a .tar despite not being a .tar archive.
Error Output:
Solution: Find a new copy of the .tar or .tar.gz file, or try extracting with gunzip 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.
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.
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.
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.
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:
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.
Related Questions
- How to join ktm orange brigade?
- How to import putty sessions into mremoteng?
- How to enable picture in picture mode in whatsapp?
- How to improve iphone xr camera quality?
- How to power cisco phone?
- How to cite a video in youtube?
- How to translate in marathi?
- How to cheat in skribbl.io?
- How to ca in india?
- How do you use the gua sha?