Ubuntu

How to Extract a Tar.bz2 File in Ubuntu?

Files in Ubuntu can often occupy more space and it usually makes file management a hectic task for administrators dealing with multiple files. Ubuntu offers the “tar” command for file management which can compress multiple files into one single file for easy management and file sharing. Those compressed archive files can then be extracted with the “tar” command once required.

In this article, the extracting process of the “tar.bz2” file in Ubuntu is explained.

How to Extract a Tar.bz2 File in Ubuntu?

The “tar” command is used widely in Ubuntu for file management. With the “tar” command, you can compress a file and can also uncompress/decompress or extract an archive file. The steps below explain the extraction process of the “tar.bz2” file.

Step 1: Open Terminal

Open the terminal by clicking on the “Application Menu” icon on the bottom left of the Home Screen:

In the Application Menu, you will see the “search bar” box on top of the menu:

Click on the Search Box and type the application you want to search. In our case, Terminal:

Click on the Terminal Icon to Run the Terminal:

Instead of going to the Application Menu and searching for Terminal, you can open the terminal directly using the “ctrl+alt+t” shortcut key:

Step 2: Navigate to the Directory containing the “tar.bz2” File

Open the “tar.bz2” file directory with the “cd” command:

cd <directory-path>

In our case, the “tar.bz2” file is in the Documents Directory. To navigate to the Documents Directory, use the command:

cd Documents

The Path in Terminal will change to the Documents Directory:

Inside the Directory, you can see the “tar.bz2” file by listing the files in the directory using the command:

ls

The “tararchive” file can be seen in the terminal:

Step 3: Extract the “tar.bz2” File

The tar command extracts the “tar.bz2” file by using the below command:

tar <fileName>.tar.bz2

In our case, the filename is “tararchive”. Thus to extract the file, the tar command used will be:

sudo tar -xjf tararchive.tar.bz2

The “-xjf” flag ensures the tar command extracts the file:

The command line moves to the next line indicating the archive file was extracted. In our case, the tar archive file contained the “FolderA” and “FolderB” Directories. To verify the extracted files, the ls command can be used again:

ls

Here, the “FolderA” and “FolderB” in the list ensure the archive file was extracted using the tar command:

Bonus Step: Compressing File into a “tar.bz2” Archive

You can also compress files into an archive file using the “tar” command. In our case, we have the “FolderA” and “FolderB” in the Documents Directory:

To Compress the Directories into a “tar.bz2” Archive File, the command used will be:

sudo tar -cjf tararchive.tar.bz2 FolderA FolderB

This will compress the Directories into the “tararchive.tar.bz2” file:

The “-cjf” ensures the tar command compresses the files or directories.

Once compressed, use the “ls” command to verify the compressed “tararchive.tar.bz2” file:

Conclusion

The “tar” is a useful command in Ubuntu for extracting files. To extract the “tar.bz2” file in Ubuntu, the tar command is used along with the “-xjf” flag ensuring the tar command extracts the file. This article explained the process of extracting a “tar.bz2” file in Ubuntu.

Similar Posts