Tar gz how to untar
Tar gz how to untar
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.
List of content you will read in this article:
What is TAR? [Definition]
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.
These files are commonly known as ‘tarballs’. They are used by Linux, macOS, or even Windows users for backups or data archival.
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.
How to extract tar.gz file in Linux?
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:
Easy, right? But somehow if your work impedes and you don’t get the desired results, follow another method.
And your work is done.
Sometimes you get an error message like this:
It implies that the files that you want to extract don’t exist.
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!
How to untar tar.gz files in Windows?
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.
Step 1. Tap on Start on your Windows
Step 2. Now, go to the Command Prompt and click right. Choose Run as Administrator option
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.
Conclusion
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.
18 Tar Command Examples in Linux
The Linux “tar” stands for tape archive, which is used by a large number of Linux/Unix system administrators to deal with tape drives backup.
The tar command is used to rip a collection of files and directories into a highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux.
The tar is the most widely used command to create compressed archive files and that can be moved easily from one disk to another disk or machine to machine.
Linux Tar Command Examples
In this article, we will be going to review and discuss various tar command examples including how to create archive files using (tar, tar.gz, and tar.bz2) compression, how to extract archive file, extract a single file, view content of the file, verify a file, add files or directories to the existing archive file, estimate the size of tar archive file, etc.
The main purpose of this guide is to provide various tar command examples that might be helpful for you to understand and become an expert in tar archive manipulation.
1. Create tar Archive File in Linux
The below example command will create a tar archive file tecmint-14-09-12.tar for a directory /home/tecmint in the current working directory. See the example command in action.
Let’s discuss each option used in the above command to create a tar archive file.
2. Create tar.gz Archive File in Linux
To create a compressed gzip archive file we use the option as z. For example, the below command will create a compressed MyImages-14-09-12.tar.gz file for the directory /home/MyImages. (Note: tar.gz and tgz both are similar).
3. Create tar.bz2 Archive File in Linux
The bz2 feature compresses and creates an archive file less than the size of the gzip. The bz2 compression takes more time to compress and decompress files than gzip, which takes less time.
To create a highly compressed tar file we use the option j. The following example command will create a Phpfiles-org.tar.bz2 file for a directory /home/php. (Note: tar.bz2 and tbz is similar to tb2).
4. Untar tar Archive File in Linux
To untar or extract a tar file, just issue the following command using option x (extract). For example, the below command will untar the file public_html-14-09-12.tar in the present working directory.
5. Uncompress tar.gz Archive File in Linux
6. Uncompress tar.bz2 Archive File in Linux
To Uncompress the highly compressed tar.bz2 file, just use the following command. The below example command will untar all the .flv files from the archive file.
7. List Content of tar Archive File in Linux
To list the contents of the tar archive file, just run the following command with option t (list content). The below command will list the content of the uploadprogress.tar file.
8. List Content tar.gz Archive File in Linux
Use the following command to list the content of the tar.gz file.
9. List Content tar.bz2 Archive File in Linux
To list the content of the tar.bz2 file, issue the following command.
10. Untar Single file from tar File in Linux
To extract a single file called cleanfiles.sh from cleanfiles.sh.tar use the following command.
11. Untar Single file from tar.gz File in Linux
To extract a single file tecmintbackup.xml from the tecmintbackup.tar.gz archive file, use the command as follows.
12. Untar Single file from tar.bz2 File in Linux
To extract a single file called index.php from the file Phpfiles-org.tar.bz2 use the following option.
13. Untar Multiple files from tar, tar.gz, and tar.bz2 File
To extract or untar multiple files from the tar, tar.gz, and tar.bz2 archive file. For example, the below command will extract “ file 1” “ file 2” from the archive files.
14. Extract Group of Files using Wildcard in Linux
15. Add Files or Directories to tar Archive File in Linux
To add files or directories to the existing tar archive files we use the option r (append). For example, we add file xyz.txt and directory php to the existing tecmint-14-09-12.tar archive file.
16. Add Files or Directories to tar.gz and tar.bz2 Files
The tar command doesn’t have an option to add files or directories to an existing compressed tar.gz and tar.bz2 archive file. If we do try will get the following error.
17. How To Verify tar, tar.gz, and tar.bz2 Archive File
To verify any tar or compressed archived file we use the option W (verify). To do this, just use the following examples of commands. (Note: You cannot do verification on a compressed ( *.tar.gz, *.tar.bz2 ) archive file).
18. Check the Size of the tar, tar.gz, and tar.bz2 Archive File
To check the size of any tar, tar.gz, and tar.bz2 archive file, use the following command. For example, the below command will display the size of the archive file in Kilobytes (KB).
Tar Usage and Options
That’s it for now, hope the above tar command examples are enough for you to learn, and for more information please use the man tar command.
If you are looking to split any large tar archive file into multiple parts or blocks, just go through this article:
If we’ve missed any examples please do share with us via the comment box and please don’t forget to share this article with your friends. This is the best way to say thanks…..
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
How to Untar Files in Linux
Tar is quite a popular archive format, especially on Linux. In many cases, distros use tar archives to deliver package updates. Tar archives are also common to find when it comes to sharing files online.
Check out how to untar files in Linux.
Tar in Linux
For managing tar archives, all the Linux distros come with the tar tool. It’s this tool that we’ll use for extracting the contents of a tar archive.
Let’s demonstrate everything with an example. First, let’s create a tar archive with several files and directories. Here, I’ve created a directory with the name “Ants” that will be transformed into a tar archive.
Now, let’s make a tar archive out of the directory. Here, tar will use various compression algorithms to do the job. It’s a common practice that the compression algorithm dictates the output file name.
To create a tar archive using gzip compression, use the following command.
To create a tar archive using bzip2 compression, use the following command.
To create a tar archive using XZ compression, use the following command.
Extracting tar files
List tar content
The following tar command will list all the files and directories included in the tar archive.
Let’s have a quick breakdown of the flags we used.
Extract entire file
Now, we’re ready to extract the tar archives we’ve got at hand. While you needed to use different commands to create different types of tar archives, we can use only a single tar command to extract all of them.
The following tar command will extract any valid tar archive. If files with similar filenames exist, upon extraction, tar will overwrite the files outside the archive.
Here, we’re facing one new tar flag.
If you don’t want tar to overwrite existing data, add the “-k” flag. It tells tar not to overwrite/replace any existing file or directory.
Extract specific files
There are some situations where you don’t need the entire tar archive extracted only to grab a single file. The tar tool offers such flexibility that you can extract only the select few files you need.
For this task, the tar command structure would look like this. Here, the file name would be the file name of your desired file. It must match with the file name that’s inside the tar archive.
If you want to extract a couple of files in such a manner, use the following command structure.
Extract specific directories
This is yet another awesome feature of the tar archive. Assuming the tar archive at your hand contains a directory or more, you can manually tell tar which directory to extract.
The command structure is similar to the section above.
If you want to extract multiple directories, then run the following command.
Final thoughts
Extracting tar archives is quite a simple task. All you need to know is the right tar command. If you’re interested in performing the actions with GUI and using a file manager, then your file manager should have the ability to extract tar archives by default.
In Linux, there are more tools to extract various formats of compressed archives. Check out how to extract compressed archives in Linux.
About the author
Sidratul Muntaha
Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.
For starters I have checked most of the solutions available no
4 Answers 4
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
Problem
You want to decompress all compressed files inside a directory and all its subdirectories.
Solution
Use bash and the utility find to output to the console a list of all contents from the present directory. Use a looping construct to decompress each file.
Decompress all files in the current directory:
Decompress all archives in the current directory and any subdirectories (my personal favorite):
Decompress all archives recursively and do the same again for any remaining:
You could use variants of this for loop, if you like adventure 🙂
Discussion
The utility find lists everything from your present directory, and is fast. The snippet below will decompress the files one directory at a time each time but illustrates the simple logic of all the following code. Above are options and variations that do solve this problem; I was assuming at first that your present working directory contains all the files that you want to decompress to use the simplest version of the snippet.
This pseudo code tries to communicate the logic behind my solution briefly:
Linux Untar
By Alokananda Ghoshal
Definition of Linux Untar
Untar is defined as a command which enables users to extract files that are compressed with tar, tar.gz, tar.bz2 formats of compression. This command is used for 2 specific utilities in file operations. It first helps the user to extract or in other words unpack files in the compressed mode and once the unpacking or extraction is done, the command helps the user to uncompress the same. Listing content, extraction of a single file, or directory are some of widely used utilities of the command untar. In this article, we will go through all the utilities of the command and take deep dive using some examples to understand them in even greater detail!
Syntax:
Web development, programming languages, Software testing & others
In Linux, there are lesser options available for untar in comparison to other extensively used commands, and we will discuss about all of those in detail here in this section and later in the article take a dig at the working of untar command in Linux.
1. Extraction of tar file
Syntax:
2. Extraction of tar.gz file
Syntax:
3. Extraction of tar.bz2 file
Syntax:
4. Untar tar archive File at desired location
Syntax:
5. List Content of tar Archive File
Syntax:
6. List Content of tar.gz Archive File
Syntax:
7. List Content of tar.bz2 Archive File
Syntax:
8. Extract single file from tar Archive File
Syntax:
9. Extract all files from tar Archive File matching a particular file regex
Syntax:
How Untar Command works in Linux?
In recent times most of our files that are downloaded from internet are compressed using a particular compression format and that is where a few of the formats are, tar, tar.gz, tar.bz2. The history behind, tar is; in early times tar file format was used for creation of archives to store files on magnetic tape, and hence the full form of tar is Tape ARchive. Untar is a process of reversion of the process which leads to formation of the tar file.
In the computation world, there are two different versions of tar, namely BSD tar and GNU tar. By default, most of the Linux are pre-installed with GNU tar. Another similar process of untar is gzip utility with the command gunzip. Now, talking about the different options of utility of untar they are the following 4 options:
x – provides option to the tar command to extract files from the given tar file.
v – commands the tar to list out the files as they get extracted.
z – commands the tar command to decompress, without which by default the tar command will compress instead of decompressing.
f – helps to specify the filename which needs to be worked on for the untar process.
In the above few options, we look at all those utilities which are widely used. Apart from this, we also have other utilities like:
With all the utilities mentioned above, this command becomes an inadvertent skill set any Linux developer possesses.
Examples
Let us discuss examples of Linux Untar.
Example #1
Extraction of tar file
Syntax:
Output
Here we see that at first there are no such files present while we have the directory, but as we untar the file, all the file contents get extracted and uncompressed to the location where we are running the command from. Similar explanation goes for the below 2 examples as well (for tar.gz and tar.bz2).
Example #2
Extraction of tar.gz file
Syntax:
Output:
Example #3
Extraction of tar.bz2 file
Syntax:
Output:
Example #4
Untar tar archive File at desired location
Syntax:
Output:
Here we see that the location desiredLoc has no files under it, and as we extract the file, all the file contents get extracted to the location specified i.e. desiredLoc.
Example #5
List Content of tar Archive File
Syntax:
Output:
Example #6
List Content of tar.gz Archive File
Syntax:
Output:
Example #7
List Content of tar.bz2 Archive File
Syntax:
Output:
Example #8
Extract single file from tar Archive File
Syntax:
Output:
Example #9
Extract all files from tar Archive File matching a particular file regex
Syntax:
Output:
In this example, we see that only the files which had “txt” as an extension gets untarred in the location!
Conclusion
With the set of examples and explanation of way of working for untar command, the usage and utilizes are even more clear for the readers and now we leave it up to you to experiment more with the different permutation combination possible with the options present in the command utility. Though not mandatory, advisable to use untar command for any of the uncompressing process of a tar, tar.gz, tar.bz2 file types as these will always have the latest options available at its disposal.
Recommended Articles
This is a guide to Linux Untar. Here we also discuss the definition, syntax, parameters, and How Untar Command works in Linux with examples. You may also have a look at the following articles to learn more –
Linux Training Program (16 Courses, 3+ Projects)