Session and utilities
The bunzip2 command
Decompresses .bz2 files back to their original names, without the extension.
Most useful options
-fOverwrites the output file if it already exists-kKeeps the .bz2 after decompressing it-sUses less memory, at the cost of running at about half the speed-vShows more information and the compression ratioCopy-ready examples
$ printf 'texto\n' > f.txt && bzip2 -k f.txt && rm f.txt && bunzip2 f.txt.bz2 && lscompresses, deletes the original and recovers it from the .bz2.Example output
f.txt
$ bunzip2 -k f.txt.bz2decompresses and keeps the .bz2. It fails if f.txt already exists.$ bzcat f.txt.bz2shows the content on screen without creating any file.$ bunzip2 -v datos.tbz2decompresses a .tbz2, which becomes datos.tar. It shows the details of the process.$ bunzip2 -f f.txt.bz2overwrites f.txt if it exists. Warning: the previous content of f.txt is lost.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| bunzip2: Output file f.txt already exists. | The output file already exists, so bunzip2 does not replace it. It happens, for example, when the original is still in the folder after using bzip2 -k. | Delete or rename the existing file, or use -f if you want to overwrite it. |
| bunzip2: f.txt is not a bzip2 file. | The file is not in bzip2 format. It may be plain text or a .gz with its extension changed. | Check the real type with file. If it is gzip, use gunzip or zcat. |
Typical mistakes
- By default the .bz2 disappears when you decompress it. With -k it is kept.
- bunzip2 does not overwrite existing files: if the destination is already there, it fails.
- If the file does not end in .bz2, bunzip2 cannot guess the output name and appends .out to it.
Differences from similar commands
- bzip2: with -d it does the same as bunzip2. The two names are the same program, and it picks the action by the name it is called with.
- bzcat: decompresses to standard output and does not touch the file. bunzip2 writes the result to disk.
- gunzip: decompresses .gz files, made by gzip. bunzip2 only handles .bz2.
FAQ
Does it delete the original?
Yes, the .bz2 disappears when you decompress it, unless you use -k.
What if the file is .bz or .tbz2?
They are handled like .bz2. A .tbz2 or .tbz becomes a .tar, so you can then unpack it with tar.
Can I decompress several files at once?
Yes, pass them all in the same command. bunzip2 also accepts files made of several .bz2 pieces joined together and rebuilds them into one.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course