How to Unzip BZ2 File

July 11, 2023

Introduction

A BZ2 file is a compressed file type for archiving large files using a Bzip2 algorithm. The algorithm provides higher compression rates while maintaining low decompression speeds.

Files with a .bz2 extension typically appear on Unix-like operating systems, but they can also be unzipped on Windows. Various utilities help extract the file's contents, and the process differs depending on the operating system.

This guide demonstrates how to unzip a BZ2 file on Linux/Unix and Windows using two methods.

How to Unzip BZ2 File

Prerequisites

  • An unzipping utility or access to the command line/terminal.
  • Sufficient disk space (see how to check disk space in Linux).
  • Read and write permissions in the destination.

How to Unzip BZ2 Files on Linux and Unix

Several tools specialize in unzipping bz2 files on Linux and Unix. The main difference is the mode of operation. Some tools work in mono-threaded mode, whereas others are multi-threaded.

The sections below demonstrate both tool types.

Method 1: Using bzip2 and bunzip2 Command

The bzip2 command compresses and decompresses BZ2 files. The tool comes preinstalled on Linux. If the command is not available on the system, install the bzip2 tool with the following:

sudo apt install bzip2

Note: Learn more on how to use Linux sudo command (with examples).

To extract a .bz2 file, open the terminal and run the following command and specify a file name:

bzip2 -d file.bz2
bzip2 -d file.bz2 terminal output

The -d option performs decompression. The alias for the command and option is bunzip2, so the following command does the same:

bunzip2 file.bz2
bunzip2 file.bz2 terminal output

The original input .bz2 file disappears after running the command. To preserve the original file, add the -k option:

bzip2 -kd file.bz2
bzip2 -kd file.bz2 terminal output

The file decompresses in the same directory and keeps the original compressed file.

Method 2: Using lbzip2 or lbunzip2 Command

The lbzip2 tool enables multi-threaded bz2 decompression. Multi-threaded decompression offers better performance when working with large files. If lbzip2 is not available by default, install it with the following command:

sudo apt install lbzip2

Use the lbzip2 command with the -d tag to switch to decompression mode. For example:

lbzip2 -d file.bz2
lbzip2 -d file.bz2 terminal output

Alternatively, use the lbunzip2 alias:

lbunzip2 file.bz2
lbunzip2 file.bz2 terminal output

The command automatically picks the number of threads. To specify the number of threads manually, use the -n option and provide the number:

lbzip2 -d -n 16 file.bz2

The command sets sixteen threads for the decompression.

How to Unzip BZ2 Files on Windows

Although bz2 files primarily appear on Linux, there are Windows programs that can unzip the file type. There is no readily-available default program on Windows, but there are plenty of third-party solutions.

For example, the 7-Zip tool offers a command line tool and GUI program to unzip bz2 files. Additional tools, such as WinZip, WinRAR, or PeaZip, all support the .bz2 file format.

The methods below use the 7-Zip program, open-source and free to use. Download it directly from the 7-Zip downloads page.

Method 1: Using CMD in Windows

To use the 7z command, do the following:

1. Open the command prompt.

2. Navigate to the .bz2 file.

3. Extract the file with the following command:

7z x file.bz2
7z x file.txt.bz2 cmd output

Note: If the command is not found, add the 7-Zip installation folder to the PATH environment variable.

4. Choose whether to replace the existing file. The 7z command completes the extraction according to the provided answer.

Method 2: Using GUI in Windows

The 7-Zip tool provides a user-friendly GUI program to extract compressed files, including files in the .bz2 format. To extract a .bz2 file, open the 7-Zip program and do the following:

1. Navigate to the file location.

2. Select the file and choose Extract in the top menu.

7-zip extract button GUI

3. A new window opens with extraction options. Choose the location and click the OK button to extract the .bz2 file.

7-zip extract location GUI

4. The extraction process creates a new folder with the same name as the file.

7-zip extracted GUI

Open the new folder to view the extracted file.

Conclusion

After reading this guide, you know what BZ2 files are and how to extract them on Linux and Windows. Archive files come in various formats, and the .bz2 format is excellent when working with large files.

Next, check out our article and learn how to unzip tar.bz2 files.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is a technical writer at phoenixNAP with a passion for programming. With a background in Electrical Engineering and Computing, coupled with her teaching experience, she excels at simplifying complex technical concepts in her writing.
Next you should read
How to Zip a File in Linux
October 31, 2022

Did you know you can work with ZIP files on Linux? The handy zip command lets you create ZIP archive files quickly. Learn how to use the command in this...
Read more
How to Unzip a ZIP File in Ubuntu / Linux
March 25, 2024

Zip files are ubiquitously used on all operating systems, including Linux. This simple guide explains how to unzip files from the command line, as well as how...
Read more
How to Extract or Unzip tar.gz Files from Linux Command Line
February 12, 2024

This article shows which commands best to use when compressing and decompressing...
Read more
tar Command in Linux With Examples
November 9, 2021

The tar command is is used to create and extract archived and compressed packages on Linux. Follow this tutorial to learn about the...
Read more