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 touch Command: Create Files and Change Timestamps

Linux touch Command: Create Files and Change Timestamps

Learn how to use the Linux touch command to create empty files and change access or modification timestamps, including reference times, date formats, and symlink handling.

Linux stat Command: Display Detailed File Metadata

Linux stat Command: Display Detailed File Metadata

Learn how to use the Linux stat command to inspect file size, permissions, ownership, timestamps, inode, and filesystem metadata, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux apropos Command: Search Commands by Description

Linux apropos Command: Search Commands by Description

Learn how to use the Linux apropos command to find relevant manual pages by searching description keywords, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux htop Command: Explore Processes Interactively

Linux htop Command: Explore Processes Interactively

Learn how to explore Processes Interactively with the Linux htop command, including practical examples, key options, and important precautions.

Linux chmod Command: Change File and Directory Permissions

Linux chmod Command: Change File and Directory Permissions

Learn how to change File and Directory Permissions with the Linux chmod command, including practical examples, key options, and important precautions.

Linux Tutorial / How the Shell Runs Commands: ;, &&, ||, Aliases, and Environment Variables

Linux Tutorial / How the Shell Runs Commands: ;, &&, ||, Aliases, and Environment Variables

Learn how Bash resolves commands and uses exit status with ;, &&, and ||, then distinguish aliases, shell variables, and exported environment variables.

Linux ssh-keygen Command: Generate SSH Keys and Inspect Fingerprints

Linux ssh-keygen Command: Generate SSH Keys and Inspect Fingerprints

Learn how to generate SSH Keys and Inspect Fingerprints with the Linux ssh-keygen command, including practical examples, key options, and important precautions.

Linux chown Command: Change File Owner and Group

Linux chown Command: Change File Owner and Group

Learn how to change File Owner and Group with the Linux chown command, including practical examples, key options, and important precautions.

Linux parted Command: Inspect and Manage Partitions

Linux parted Command: Inspect and Manage Partitions

Learn how to inspect and Manage Partitions with the Linux parted command, including practical examples, key options, and important precautions.

Linux unalias Command: Remove Command Aliases

Linux unalias Command: Remove Command Aliases

Learn how to use the Linux unalias command to remove one or all aliases from the current shell session, with essential options, practical examples, output interpretation, and common troubleshooting tips.