Tar files are compressed archives. You’ll encounter them frequently while using a Linux distribution like Ubuntu or even while using the terminal on macOS. Here’s how to extract—or untar—the contents of a tar file, also known as a tarball.
What Does .tar.gz and .tar.bz2 Mean?
- Up vote 14 down vote. A good tar utility for Windows is tar. No need to involve Cygwin, either; it can run as a native program. The UnxUtils project on Sourceforge has lots of Windows versions of common Unix utilities without the need for Cygwin. If you need a GUI, WinZip can read tarballs, and so can WinRar.
- One file is called ukulelesongs.tar.gz, the other is called guitarsongs.tar.bz2. These files are in the Downloads directory. Let’s extract the ukulele songs: tar -xvzf ukulelesongs.tar.gz As the files are extracted, they are listed in the terminal window. The command line options we used are:-x: Extract, retrieve the files from the tar file.
Files that have a
.tar.gz
or a .tar.bz2
extension are compressed archive files. A file with just a .tar
extension is uncompressed, but those will be very rare.The
.tar
portion of the file extension stands for tape archive, and is the reason that both of these file types are called tar files. Tar files date all the way back to 1979 when the tar
command was created to allow system administrators to archive files onto tape. Forty years later we are still using the tar
command to extract tar files on to our hard drives. Someone somewhere is probably still using tar
with tape.The
.gz
or .bz2
extension suffix indicates that the archive has been compressed, using either the gzip
or bzip2
compression algorithm. The tar
command will work happily with both types of file, so it doesn’t matter which compression method was used—and it should be available everywhere you have a Bash shell. You just need to use the appropriate tar
command line options.Apr 05, 2019 Forty years later we are still using the tar command to extract tar files on to our hard drives. Someone somewhere is probably still using tar with tape. The.gz or.bz2 extension suffix indicates that the archive has been compressed, using either the gzip or bzip2 compression algorithm. Jul 24, 2019 How to extract.tar.gz,.tgz, or.gz tarballs using tar on Linux on Windows 10 To use tar on Linux, you need to install a distro (such as Ubuntu) by enabling the Windows Subsystem for Linux (WSL) using the Windows Features experience, and then install Ubuntu from the Microsoft Store.
Extracting Files from Tar Files
Let’s say you’ve downloaded two files of sheet music. One file is called
ukulele_songs.tar.gz
, the other is called guitar_songs.tar.bz2
. These files are in the Downloads directory.Let’s extract the ukulele songs:
As the files are extracted, they are listed in the terminal window.
The command line options we used are:
- -x: Extract, retrieve the files from the tar file.
- -v: Verbose, list the files as they are being extracted.
- -z: Gzip, use gzip to decompress the tar file.
- -f: File, the name of the tar file we want
tar
to work with. This option must be followed by the name of the tar file.
Tar.gz Extract Windows Cmd
List the files in the directory with
ls
and you’ll see that a directory has been created called Ukulele Songs. The extracted files are in that directory. Where did this directory come from? It was contained in the tar
file, and was extracted along with the files.Now let’s extract the guitar songs. To do this we’ll use almost exactly the same command as before but with one important difference. The
.bz2
extension suffix tells us it has been compressed using the bzip2 command. Instead of using the-z
(gzip) option, we will use the -j
(bzip2) option.Once again, the files are listed to the terminal as they are extracted. To be clear, the command line options we used with
tar
for the .tar.bz2
file were:- -x: Extract, retrieve the files from of the tar file.
- -v: Verbose, list the files as they are being extracted.
- -j: Bzip2, use bzip2 to decompress the tar file.
- -f: File, name of the tar file we want tar to work with.
If we list the files in the Download directory we will see that another directory called Guitar Songs has been created.
Choosing Where to Extract the Files To
If we want to extract the files to a location other than the current directory, we can specify a target directory using the
-C
(specified directory) option.Looking in our Documents/Songs directory we’ll see the Guitar Songs directory has been created.
Note that the target directory must already exist,
tar
will not create it if it is not present. If you need to create a directory and have tar
extract the files into it all in one command, you can do that as follows:The
-p
(parents) option causes mkdir
to create any parent directories that are required, ensuring the target directory is created.Looking Inside Tar Files Before Extracting Them
So far we’ve just taken a leap of faith and extracted the files sight unseen. You might like to look before you leap. You can review the contents of a
tar
file before you extract it by using the -t
(list) option. It is usually convenient to pipe the output through the less
command.Notice that we don’t need to use the
-z
option to list the files. We only need to add the -z
option when we’re extracting files from a .tar.gz
file. Likewise, we don’t need the -j
option to list the files in a tar.bz2
file.Scrolling through the output we can see that everything in the tar file is held within a directory called Ukulele Songs, and within that directory, there are files and other directories.
We can see that the Ukulele Songs directory contains directories called Random Songs, Ramones and Possibles.
To extract all the files from a directory within a tar file use the following command. Note that the path is wrapped in quotation marks because there are spaces in the path.
To extract a single file, provide the path and the name of the file.
You can extract a selection of files by using wildcards, where
*
represents any string of characters and ?
represents any single character. Using wildcards requires the use of the --wildcards
option.Extracting Files Without Extracting Directories
If you don’t want the directory structure in the tar file to be recreated on your hard drive, use the
--strip-components
option. The --strip-components
option requires a numerical parameter. The number represents how many levels of directories to ignore. Files from the ignored directories are still extracted, but the directory structure is not replicated on your hard drive.If we specify
--strip-components=1
with our example tar file, the Ukulele Songs top-most directory within the tar file is not created on the hard drive. The files and directories that would have been extracted to that directory are extracted in the target directory.There are only two levels of directory nesting within our example tar file. So if we use
--strip-components=2
, all the files are extracted in the target directory, and no other directories are created.If you look at the Linux man page you’ll see that
READ NEXTtar
has got to be a good candidate for the title of “command having the most command line options.” Thankfully, to allow us to extract files from .tar.gz
and tar.bz2
files with a good degree of granular control, we only need to remember a handful of these options.- › How to Hide Twitter Replies
- › How to Install Apps Directly On Your Apple Watch
- › What Is a GIF, and How Do You Use Them?
- › How to Protect Your Identity Online
- › Microsoft Explains How “Cloud Download” Reinstalls Windows 10
Active7 years, 4 months ago
I use Cygwin regularly, but I have a need these days to extract tar.gz and tar.bz2 files on other people's Windows machines. They don't want Cygwin; they need a GUI. I've tried 7-zip, which some other people in our company were using, but 7-zip makes the braindead decision to require you to first uncompress a file to a new destination file, then untar the file, thus wasting time and disk space, and requiring extra actions on my part. And there's other things I don't like about its interface.
I just received a new Windows workstation and decided to try out the ZipGenius software the powers that be decided to provide with it, but it doesn't even handle tar.gz files.
Any suggestions on a better tool?
skiphoppyskiphoppy40.7k6262 gold badges158158 silver badges206206 bronze badges
closed as off topic by Rob Kennedy, Luke Woodward, Chris Gerken, Michael Dillon, CodeLikeBeakerNov 11 '12 at 17:41
Questions on Stack Overflow are expected to relate to programming within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.
8 Answers
7-Zip allows you to double click the file inside its file manager and explore it, so you can double click the tar.bz and get the tar, and double click again to get the files inside.
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
Gonzalo QueroGonzalo Quero
A good tar utility for Windows is
tar
. No need to involve Cygwin, either; it can run as a native program. The UnxUtils project on Sourceforge has lots of Windows versions of common Unix utilities without the need for Cygwin.If you need a GUI, WinZip can read tarballs, and so can WinRar. They behave the same as you describe 7-Zip, though. If you open a .tar.gz file, they first unzip the file and then open the inner tar file. There's not much you can do to avoid that in a GUI. Both the tar and gz formats are streamable, which makes them perfect for, say, piping the output from
gunzip
into tar
in order to unpack a tarball without using lots of extra disk space. But a GUI is going to offer a list of all the files in the archive, which you can't do without reading the entire tar file. A GUI will also allow you to point and click to select which single files to extract, and you can't do that without reading the entire file, either.What a GUI could do is unzip the file in memory to create an index and then discard the data, retaining only enough to display the index. Once you select the files to extract, it would unzip the tarball a second time and write the selected data to disk. But I'm not aware of any programs that do it that way. If you're that low on disk space, use the command-line method instead.
Rob KennedyRob Kennedy149k1717 gold badges239239 silver badges424424 bronze badges
Total Commander handles .tar.gz out of the box and is just the best FileSystem manager around in my book :)
Tar.gz Extract Windows Free Download
skiphoppy40.7k6262 gold badges158158 silver badges206206 bronze badges
Martijn LaarmanMartijn Laarman
ctackectacke62.4k1414 gold badges8888 silver badges145145 bronze badges
Try tartool, its a simple command line utility.
Its free and the code is open source.
Disclosure: I wrote this tool.
senthilsenthil
You can use 7-Zip, or PeaZip if you dislike 7-Zip's UI, both are free and open source.Another good choice may be WinRAR, it is non-free but just shows a nag screen at program's startup when the trial expires, not a big nag at all.
DrosophilaDrosophila
Archive eXchange from www.objectfusion.com has the best TAR support of any of the Windows software currently on the market.
JoeJoe
I've always been a big fan of ZipGenius. They support TAR formats (7zip too) and it has a lot of great features. Plus it is free.
Unpack Tar File Windows 10
Dillie-ODillie-O24.3k1414 gold badges8585 silver badges134134 bronze badges