Author: Dave McKay / Source: How-To Geek

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?
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.
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:
tar -xvzf ukulele_songs.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.
- -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.
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.
tar -xvjf guitar_songs.tar.bz2

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…
The post How to Extract Files From a .tar.gz or .tar.bz2 File on Linux appeared first on FeedBox.