Linux bunzip2 Command: Decompress bzip2 Files

bunzip2 decompresses .bz2 files. Usually, it replaces the compressed file with the original file and is used similarly to bzip2 -d.

What is the bunzip2 command?

When sample.txt.bz2 is decompressed, it becomes sample.txt. If you remove the compression layer of .tar.bz2, a tar archive remains, and the multiple files inside are extracted from the tar. If you want to keep the original compressed file, specify -k.

Basic syntax

bunzip2 [options] file.bz2 [file.bz2...]

Installed implementations and options may vary depending on the distribution. Check the description on the current system with man bunzip2.

Examples

Basic Decompression

It replaces the compressed file with a file of its original name.

bunzip2 data.csv.bz2

Keeping the Compressed File

Decompresses without deleting the original .bz2.

bunzip2 -k data.csv.bz2

Restore to standard output

Used when sending the content to another command before creating a file.

bunzip2 -c data.csv.bz2 | head

Decompression and Filename Conflicts

bunzip2 extracts .bz2 files and usually removes the compressed file. The following assumes it is run in a separate directory that does not have the same name as the original.

bunzip2 note.txt.bz2
ls -l note.txt

If successful, the first command usually produces no output, and the restored file appears with the second command. If a file with the same name already exists, you may be prompted to confirm whether to overwrite it.

To keep the compressed file and just check its contents, you can use bunzip2 -c note.txt.bz2. Do not output large files directly to the terminal; first decide whether to send them to an appropriate file or pipe. It is safe to verify the content and checksum of the file after decompression.

Main Options and Format

Options/Format Description
-k Preserves the compressed input file.
-c Sends the decompressed data to standard output.
-f Can forcibly overwrite existing target files.
-v Displays the process in detail.
-s Attempts to decompress using less memory.

Precautions when using

-f can overwrite existing restored files, so check the filenames before using it. bunzip2 is not a command to unzip ZIP files, and it does not directly extract multiple files inside a .tar.bz2. To extract the entire tar archive, use tar -xjf.

Frequently Asked Questions

What remains when you extract a.tar.bz2 with bunzip2?

A .tar archive with the bzip2 compression removed remains. Extract the files inside with tar.

Official Documentation

You can check the exact behavior of the options and implementation differences in the official documentation for bunzip2.

More in This Category
Linux Tutorial / Compare Files with diff and cmp

Linux Tutorial / Compare Files with diff and cmp

Use diff and cmp to compare two files, read unified diff output, and distinguish a detected difference from an actual command error.

Linux sftp Command: Transfer Files Securely over SSH

Linux sftp Command: Transfer Files Securely over SSH

Learn how to use the Linux sftp command to transfer and manage files securely through an SSH connection, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Tutorial / Hard Links vs. Symbolic Links in Linux: Differences and Examples

Linux Tutorial / Hard Links vs. Symbolic Links in Linux: Differences and Examples

Compare hard and symbolic links through inode and path behavior, then create both kinds of link and observe what happens when the original name changes.

Linux zypper Command: Manage Packages on openSUSE and SUSE

Linux zypper Command: Manage Packages on openSUSE and SUSE

Learn how to manage Packages on openSUSE and SUSE with the Linux zypper command, including practical examples, key options, and important precautions.

Linux w Command: Show Logged-In Users and Their Processes

Linux w Command: Show Logged-In Users and Their Processes

Learn how to show Logged-In Users and Their Processes with the Linux w command, including practical examples, key options, and important precautions.

Linux traceroute Command: Trace Routers on the Way to a Host

Linux traceroute Command: Trace Routers on the Way to a Host

Learn how to trace Routers on the Way to a Host with the Linux traceroute command, including practical examples, key options, and important precautions.

Linux shutdown Command: Schedule a Shutdown or Restart

Linux shutdown Command: Schedule a Shutdown or Restart

Learn how to schedule a Shutdown or Restart with the Linux shutdown command, including practical examples, key options, and important precautions.

Linux kill Command: Send a Signal to a Process ID

Linux kill Command: Send a Signal to a Process ID

Learn how to send a Signal to a Process ID with the Linux kill command, including practical examples, key options, and important precautions.

Linux watch Command: Run a Command Repeatedly

Linux watch Command: Run a Command Repeatedly

Learn how to use the Linux watch command to rerun a command at regular intervals and highlight changing output, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux whoami Command: Show the Effective User Name

Linux whoami Command: Show the Effective User Name

Learn how to show the Effective User Name with the Linux whoami command, including practical examples, key options, and important precautions.