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.









