This is only for .tar.* files which have the code pre-compiled but packed into a tar file. Okay, this is a fairly challenging task for a beginner, but just follow my instructions, and it should be fine. First off, download the .tar.* file, and save it. Don’t open it. (In these examples, I’ll be installing the Dropbox Beta build, because I was going to install it anyway, so I figured that I might as well document the installation.) After you’ve downloaded your file, (assuming that you saved it to Downloads,) type the following:

cd Downloads sudo cp dropbox-lnx.x86_64-1.5.36.tar.gz /opt/ 

NOTE: use the name of whatever file you downloaded. (e.g., for the Firefox Nightly 19.0a1 64-bit build, you would type sudo cp firefox-19.0a1.en-US.linux-x86_64.tar.bz2 /opt/) Now, change to the /opt/ directory, extract the program, and remove the old file:

cd /opt/ sudo tar -xvf dropbox-lnx.x86_64-1.5.36.tar.gz sudo rm -rf dropbox-lnx.x86_64-1.5.36.tar.gz 

(again, use the name of the downloaded file. Don’t forget the extension.) Okay, check to see what the extracted folder is called:

ls -a 

you’ll get something like this:

[email protected]:/opt$ ls -a . .. .dropbox-dist [email protected]:/opt$ 

Okay, in our example, we installed Dropbox, and the only folder there is called .dropbox-dist. That’s probably the folder we want, so plug that in to the next step (add a / to the end, since it’s a folder.):

sudo chmod 777 .dropbox-dist/ 

Okay, it’s now marked as executable, so it’s time to create a symbolic link (this is what allows you to run it from the Terminal):

sudo ln -s /opt/.dropbox-dist/ /usr/bin/dropbox 

NOTE: this is sudo ln -s /opt/{FOLDER_NAME}/ /usr/bin/{PROGRAM_NAME}!!! Be sure that {PROGRAM_NAME} is replaced with the simplified, lower-case version of the program’s name (e.g., for Firefox Nightly, type firefox-nightly; for the uTorrent server, type utserver. Whatever you type here will be the command that you use whenever running the program from the Terminal. Think of /usr/bin/ as like the PATH variable on Windows systems.) Okay, you’re done. The program is now installed and runnable from the Terminal.
What’s this? You say you want to run it from the launcher, AND you want it to have an icon? No problem! This part is fairly simple:

gksu gedit /usr/share/applications/dropbox.desktop 

NOTE: If you’re installing OVER a previous installation, use ls -a /usr/share/applications and search for pre-existing .desktop file. Plug that file’s name in instead. Now, here’s where you create the icon. Here’s good template; edit it appropriately.

[Desktop Entry] Version=1.0 Name=Firefox Nightly Comment=Browse the World Wide Web GenericName=Web Browser Keywords=Internet;WWW;Browser;Web;Explorer Exec=firefox-nightly Terminal=false X-MultipleArgs=false Type=Application Icon=/opt/firefox/icons/mozicon128.png Categories=GNOME;GTK;Network;WebBrowser; MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ftp;x-scheme-handler/chrome;video/webm;application/x-xpinstall; StartupNotify=true Actions=NewWindow; [Desktop Action NewWindow] Name=Open a New Window Exec=firefox-nightly -new-window OnlyShowIn=Unity; 

You may want to leave off the MimeType option completely. That could be very bad if you didn’t. Now, click «Save», close it out, and you’re in business! Bash shell on Unity desktop conceptFatmawati Achmad Zaenuri/ 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. Two tar files 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. Extraction of all files from tar file 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. Ukulele Songs directory created in Downloads directory 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

Extraction of guitar songs tar file in Downloads folder 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. Guitar songs directory created in Downloads directory

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.

tar -xvjf guitar_songs.tar.gz -C ~/Documents/Songs/

Looking in our Documents/Songs directory we’ll see the Guitar Songs directory has been created. Guitar songs directory created in Documents/Songs directory 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:

mkdir -p ~/Documents/Songs/Downloaded && tar -xvjf guitar_songs.tar.gz -C ~/Documents/Songs/Downloaded/

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.

tar -tf ukulele_songs.tar.gz | less

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. Contents of tar file piped through less 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. Second view of contents of tar file piped through less 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.

tar -xvzf ukulele_songs.tar.gz "Ukulele Songs/Ramones/"

Extracting single folder from tar file To extract a single file, provide the path and the name of the file.

tar -xvzf ukulele_songs.tar.gz "Ukulele Songs/023 - My Babe.odt"

Extracting single file from tar 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.

tar -xvz --wildcards -f ukulele_songs.tar.gz "Ukulele Songs/Possibles/B*"

Extracting songs from tar with wildcards

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.

tar -xvzf ukulele_songs.tar.gz --strip-components=1

Extracting files from tar file with --strip-components=1 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.

tar -xvzf ukulele_songs.tar.gz --strip-components=2

Extracting files from tar file with --strip-components=2 If you look at the Linux man page you’ll see that tar 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. READ NEXT

  • › How to Use the FTP Command on Linux
  • › How to Install and Use the Tor Browser on Linux
  • › 37 Important Linux Commands You Should Know
  • › How to Zip or Unzip Files From the Linux Terminal
  • › Chromebooks Can Now Unzip More Than ZIP Files
  • › How to Remove Followers on Instagram
  • › How to Sign Out of Google on All Your Devices
  • › Astronomers Discover Closest Black Hole to Earth (Which is Still Far)

The tar command allows you to create and extract tar archives. It supports a vast range of compression programs such as gzip, bzip2, lzip, lzma, lzop, xz and compress. Bzip2 is one of the most popular algorithms for compressing tar files. By convention, the name of a tar archive compressed with bzip2 ends with either .tar.bz2 or .tbz2. In this tutorial, we will explain how to extract (or unzip) tar.bz2 and tbz2 archives using the tar command. Most Linux distributions and macOS comes with the tar utility pre-installed by default. To extract a tar.bz2 file, use the --extract (-x) option and specify the archive file name after the -f option:

tar -xf archive.tar.bz2

The tar command auto-detects compression type and extracts the archive. The same command can be used to extract tar archives compressed with other algorithms such as .tar.gz
or or .tar.xz
. If you are a Desktop user and the command-line is not your thing you can use your File manager. To extract (unzip) a tar.bz2 file simply right-click the file you want to extract and select “Extract”. Windows users will need a tool named 7zip
to extract tar.bz2 files. For more verbose output use the -v option. This option tells tar to display the names of the files being extracted on the terminal.

tar -xvf archive.tar.bz2

By default, tar will extract the archive contents in the current working directory
. Use the --directory (-C) to extract archive files in a specific directory: For example, to extract the archive contents to the /home/linuxize/files directory, you would type:

tar -xf archive.tar.bz2 -C /home/linuxize/files

To extract a specific file(s) from a tar.bz2 file, append a space-separated list of file names to be extracted after the archive name:

tar -xf archive.tar.bz2 file1 file2

When extracting files, you must provide their exact names including the path, as printed when the --list (-t) option is used. Extracting one or more directories from an archive is the same as extracting multiple files:

tar -xf archive.tar.bz2 dir1 dir2

If you try to extract a file that doesn’t exist in the archive, an error message similar to the following will be shown:

tar -xf archive.tar.bz2 README
tar: README: Not found in archive tar: Exiting with failure status due to previous errors 

The --wildcards option allows you to extract files from a tar.bz2 file based on a wildcard pattern. The pattern must be quoted to prevent the shell from interpreting it. For example, to extract only the files whose names end in .md (Markdown files), you would use:

tar -xf archive.tar.bz2 --wildcards '*.md'

When extracting a compressed tar.bz2 file by reading the archive from standard input (usually through piping), you must specify the decompression option. The -j option tells tar that the file is compressed with bzip2. In the example below we are downloading the Vim sources using the wget
command and pipe its output to the tar command:

wget -c -O - | sudo tar -xj

If you don’t specify a decompression option, tar will show you which option you should use:

tar: Archive is compressed. Use -j option tar: Error is not recoverable: exiting now 

Listing tar.bz2 File

To list the content of a tar.bz2 file, use the --list (-t) option:

tar -tf archive.tar.bz2

The output will look something like this:

file1 file2 file3 

If you add the --verbose (-v) option, tar will print more information, such as owner, file size, timestamp ..etc:

tar -tvf archive.tar.bz2
-rw-r--r-- linuxize/users 0 2019-02-15 01:19 file1 -rw-r--r-- linuxize/users 0 2019-02-15 01:19 file2 -rw-r--r-- linuxize/users 0 2019-02-15 01:19 file3 


tar.bz2 file is a Tar archive
compressed with Bzip2. To extract a tar.bz2 file, use the tar -xf command followed by the archive name. If you have any questions, please leave a comment below. In this tutorial, we will be showing you how to use tar command to extract tar.bz2 files. Tar stands for tape archive, and it is one of the most used commands that deals with compressed archive files. Bz2 stands for bzip2. It is a specific compression algorithm. The tar command comes pre-installed in most Linux distributions. The tar utility is used to compress and extract files using different algorithms. Tar supports a wide array of compression algorithms such as gzip, bzip2, xz, lzip, etc.

Table of Contents
  1. Extract a tar.bz2 file quickly
  2. Basic usage of tar command
    1. Listing the contents of a tar bz2 archive
    2. Extract specific files/folders from a tar bz2 archive
    3. Change the location of extraction
  3. Conclusion

In this section, we’ll show you a simple method to extract any tar.bz2 file. In the later sections, you will get to know the tar command in a little bit more detail. To extract all the files inside of a tar.bz2 file, use the -xf flag with the tar command:

tar -xf file.tar.bz2

Here, x stands for extract and f stands for the archive file. The tar command detects the compression type automatically and extracts it. You don’t need to specify the file/compression type to extract. For example, you could extract a tar.gz file with the same command. Alternatively, you can also use the graphical user interface (GUI) instead of the command line. Just right click on the tar bz2 archive file you want to extract and click on the Extract option.

Basic usage of tar command

The basic syntax of the tar command is as follows:

tar [options] [file]

The tar command has a plethora of options in the help menu. You can access it by typing in tar --help. We’ll be using the main operation mode most of the time. This mode has some basic options for creating and extracting archives. Below are three of these options:

-c, – create create a new archive -t, – list list the contents of an archive -x, – extract, – get extract files from an archive

You’ve already seen the usage of the -x flag for extracting an archive. Let’s take a look at some other options now.

Listing the contents of a tar bz2 archive

If you just wanted to take a look at the contents of an archive, you would use the -t or --list flag:

tar -tf compressed_file.tar.bz2


file file.log file.txt

We can get more details about the archive using the -v or --verbose flag with the command. The output will include file/folder details such as owner, permissions, etc. Let’s see it in action:

tar -tf compressed_file.tar.bz2


-rw-r--r – root/root 3153920 2021-10-15 21:55 file -rw-r--r – edxd/edxd 1048576 2021-10-15 21:54 file.txt -rw-r--r – root/root 2097152 2021-10-15 21:54 file.log

As you can see, the file permissions and owner along with the file size is shown in the output. Imagine you need a specific file from a large archive. In this case, you might want to only extract that specific file from the archive. This can be done by simply specifying the filename (and file path) followed by the extract command. Let’s see how to extract only the required files: Check what files are in the working directory with the ls command:



compressed_file.tar.bz2 file.tar.bz2 tutorial.firstpage.php

I have already shown you the content of the compressed_file.tar.bz2 in the previous section (listing files). Now let’s extract file and file.log from this archive. We’ll be using the following command:

tar -xf compressed_file.tar.bz2 file file.log

Here, we used the -xf flag with the command to extract the compressed_file.tar.bz2 archive. We also mentioned file and file.log indicating which files to extract. Now let’s check our working directory again with the ls command:

compressed_file.tar.bz2 file file.log file.tar.bz2 tutorial.firstpage.php

As you can see, the file and file.log have been extracted from the compressed_file.tar.bz2 archive. You can also extract specific directories/folders by using this method. The command would look like the following:

tar -xf archive.tar.bz2 dir1 dir2 dir3

Here, dir1, dir2, and dir3 are the names of the directories/folders you want to extract from the archive.

Use wildcards for specific file extensions

Let’s say you want to extract all the files that have the same extension from inside of an archive. In this case, you could use a wildcard like *.extension format. Here, you can use your specific extension. For example, if you wanted to extract all the text files, you would use *.txt. Let’s see this in action: First, let’s take a look at our current directory:



compressed_file.tar.bz2 file.tar.bz2 test.tar.bz2

Let’s take a look at the files inside the test.tar.bz2 archive:

tar -tf test.tar.bz2


file.log tutorial.firstpage.php num.txt pr_ex_creator.txt

Now, we have two text files that end in .txt extension. Let’s extract these two files with the *.txt wildcard. We also need to use the --wildcards flag to enable the wildcard option:

tar -xf test.tar.bz2 – wildcards *.txt

Now let’s check our current directory to see if it worked –



compressed_file.tar.bz2 file.tar.bz2 num.txt pr_ex_creator.txt test.tar.bz2

From the output, we can see that those two text files were extracted. This is how you can use wildcards to extract all the files with a specific extension. If you want to change the location where the extracted files will occupy, you can use the -C flag and specify the location of your choice. Here’s an example of how to do it:

tar -xf compressed_file.tar.bz2 -C /home/new/

Here, after the -C flag, I’ve specified the path for saving the extracted files. The path /home/new/ is marked in color. Let’s take a look at the contents of the directory:

ls /home/new/


file file.log file.txt

As you can see, the compressed_file.tar.bz2 file extracted in the /home/new/ location.


In this tutorial, we showed you how to extract a tar.bz2 archive. In brief, you can extract the archive using the -xf flag with the tar command. If you’re still unsure how to use the tar command, you can use the graphical user interface when possible – you can also see check out some examples from the help menu. Thank you for reading. If you have any questions, feel free to leave them in the comments section below.

Leave a comment

Your email address will not be published. Required fields are marked *