lbzip2 — quick reference
Compression
Create .bz2 files with the same format as bzip2. By default the original file is removed after a successful compress.
| When to use | Command |
|---|---|
Compress a file (replaces the original with file.bz2) |
lbzip2 file.txt |
Force compression when invoked as lbunzip2 or lbzcat |
lbzip2 -z file.txt |
| Keep the original file after compressing | lbzip2 -k file.txt |
| Overwrite an existing output file or re-compress a changed file | lbzip2 -f file.txt |
| Compress several files in one run | lbzip2 file1.txt file2.txt |
| Read from stdin when no file is given (filter mode) | lbzip2 < file.txt > file.txt.bz2 |
Decompression
Expand .bz2 data back to plain files or stdout. lbunzip2 and lbzcat are the same program with different defaults.
| When to use | Command |
|---|---|
Decompress file.bz2 (removes the .bz2 by default) |
lbzip2 -d file.txt.bz2 |
Same as above using the lbunzip2 name |
lbunzip2 file.txt.bz2 |
Decompress and keep the .bz2 file |
lbzip2 -dk file.txt.bz2 |
| Write decompressed data to stdout | lbzip2 -dc file.txt.bz2 |
Same with the lbzcat program name |
lbzcat file.txt.bz2 |
Performance
Tune thread count, block size, and memory use for large logs or backup archives.
| When to use | Command |
|---|---|
| Use N worker threads (auto-detect if omitted) | lbzip2 -n 4 file.txt |
Fastest block size (100K; alias --fast) |
lbzip2 -1 file.txt |
Largest block size (900K; default; alias --best) |
lbzip2 -9 file.txt |
| Lower memory use at the cost of speed | lbzip2 -s file.txt |
| Process input blocks sequentially (may help ratio on some data) | lbzip2 -u file.txt |
Output, testing, and logging
Send compressed bytes to a pipe, verify archives, or print progress on stderr.
| When to use | Command |
|---|---|
Write compressed output to stdout (implies -k on files) |
lbzip2 -c file.txt |
| Test integrity without writing decompressed files | lbzip2 -t file.txt.bz2 |
| Log each job and show ratio or progress on a terminal | lbzip2 -v file.txt |
Help and version
| When to use | Command |
|---|---|
| Show built-in usage | lbzip2 --help |
| Show version and license | lbzip2 --version |
lbzip2 — command syntax
Synopsis from lbzip2 --help on Ubuntu 25.04 (lbzip2 2.5):
lbzip2 [-n WTHRS] [-k|-c|-t] [-d|-z] [-1 .. -9] [-f] [-v] [-S] {FILE}
lbzip2 -h|-VProgram names lbunzip2, lbzcat, bunzip2, and bzcat select decompress or stdout modes automatically. lbzip2 does not edit system config files; it only reads input files and writes .bz2 or restored filenames.
lbzip2 — command examples
Essential Compress a file with default settings
Use this for everyday log rotation or shrinking a single large text file. lbzip2 replaces the original with a .bz2 file using the default -9 block size.
Run the command:
echo 'hello lbzip2 test content for compression' > sample.txt
lbzip2 -v sample.txt
ls -la sample.txt.bz2Sample output:
lbzip2: compressing "sample.txt" to "sample.txt.bz2"
lbzip2: "sample.txt": compression ratio is 1.738:1, space savings is -73.81%
-rw-r--r-- 1 root root 73 Jul 1 17:54 sample.txt.bz2The original sample.txt is gone unless you used -k. Confirm only the archive remains:
ls sample.txt 2>&1Sample output:
ls: cannot access 'sample.txt': No such file or directorySmall files can end up larger than the source — that is normal for bzip2 on tiny inputs.
Essential Decompress a .bz2 file
Restore plain text from an archive created by lbzip2 or classic bzip2.
Run the command:
lbzip2 -d sample.txt.bz2
cat sample.txtSample output:
hello lbzip2 test content for compressionAfter -d, the .bz2 file is removed by default. Use -k when you need both the archive and the extracted file.
Common Compress without deleting the source file
Keep the original when you still need the plain file online or want a safety copy before shipping the archive elsewhere.
Run the command:
echo 'keep me' > keep.txt
lbzip2 -k keep.txt
ls -la keep.txt keep.txt.bz2Sample output:
-rw-r--r-- 1 root root 8 Jul 1 17:54 keep.txt
-rw-r--r-- 1 root root 47 Jul 1 17:54 keep.txt.bz2Both files remain on disk — handy before uploading keep.txt.bz2 to backup storage.
Common Create a tar.bz2 archive with lbzip2
tar can call lbzip2 as the compressor so directory trees are archived and compressed in one step on multi-core hosts.
Run the command:
mkdir -p folder && echo 'inside folder' > folder/inner.txt
tar --use-compress-program=lbzip2 -cf archive.tar.bz2 folder/
tar --use-compress-program=lbzip2 -tf archive.tar.bz2Sample output:
folder/
folder/inner.txtList mode proves the archive is readable. Extract later with tar --use-compress-program=lbzip2 -xf archive.tar.bz2.
Common Limit worker threads for shared servers
On busy hosts, cap CPU use with -n instead of letting lbzip2 grab every core.
Run the command:
echo 'thread test data' > thread.txt
lbzip2 -n 2 -v -k thread.txtSample output:
lbzip2: compressing "thread.txt" to "thread.txt.bz2"
lbzip2: "thread.txt": compression ratio is 3.059:1, space savings is -205.88%Check the archive exists:
ls -la thread.txt thread.txt.bz2Sample output:
-rw-r--r-- 1 root root 17 Jul 1 17:54 thread.txt
-rw-r--r-- 1 root root 52 Jul 1 17:54 thread.txt.bz2Omit -n on dedicated backup boxes when you want maximum throughput.
Common Trade speed for block size with -1 and -9
-1 uses 100K blocks (--fast); -9 uses 900K blocks and is the default (--best). Pick -1 for quick passes and -9 when size matters most.
Run the command:
echo 'fast level' > fast.txt
lbzip2 -1 -k fast.txt
ls -la fast.txt.bz2Sample output:
-rw-r--r-- 1 root root 50 Jul 1 17:54 fast.txt.bz2Compare mentally with a -9 run on the same data when tuning backup windows.
Advanced Test a .bz2 file without extracting
Run -t after copying archives off-site or when a download might be truncated. No output files are written.
Run the command:
lbzip2 -t sample.txt.bz2
echo exit:$?Sample output:
exit:0A non-zero exit means the archive is corrupt or not valid bzip2 data.
Advanced Stream compressed bytes to another program
-c writes to stdout and keeps input files (implies -k). Use it in pipelines when you do not want a temporary .bz2 on disk.
Run the command:
echo 'stdout test' > stdout.txt
lbzip2 -c stdout.txt | wc -c
lbzip2 -dc stdout.txt.bz2Sample output:
50
hello lbzip2 test content for compressionThe byte count is the compressed size. Decompress from the saved archive with -dc when you need the text back.
lbzip2 — when to use / when not
| Use lbzip2 when | Use something else when |
|---|---|
|
lbzip2 vs bzip2
Both tools produce standard .bz2 streams. The difference is parallelism and defaults on the wrapper binary.
| lbzip2 | bzip2 | |
|---|---|---|
| Threading | Multi-threaded (-n WTHRS) |
Single-threaded |
| Speed on many-core hosts | Usually faster | Usually slower |
| Output format | .bz2 (compatible) |
.bz2 |
| Install | Extra package (apt install lbzip2) |
Often preinstalled |
| Best for | Large files, tar pipelines, backups | Minimal installs, scripts that assume bzip2 in PATH |
Decompressing with either tool works on archives from the other. See the bzip2 command for the single-threaded tool.
Related commands
Compression and archiving tools often used in the same backup or log-rotation workflows.
| Command | One line |
|---|---|
| lbzip2 | Multithreaded .bz2 compress/decompress (this page) |
| tar | Bundle directories; pair with lbzip2 via --use-compress-program |
| gzip | Fast .gz compression; ubiquitous default on Linux |
Browse the full index in our Linux commands reference.
lbzip2 — interview corner
What is lbzip2 in Linux?
lbzip2 is a parallel implementation of the bzip2 compressor. It uses the same .bz2 file format, so archives remain compatible with bzip2, bunzip2, and tar -j, but work is split across several threads (-n) on multi-core CPUs.
Install on Debian/Ubuntu with sudo apt install lbzip2. Verify with:
lbzip2 --versionSample output:
lbzip2 version 2.5A strong answer is:
"lbzip2 is a multithreaded bzip2-compatible compressor. It produces standard .bz2 files but uses multiple CPU threads so large log and backup jobs finish faster than classic bzip2."
What is the difference between lbzip2 and bzip2?
Both read and write the bzip2 bitstream. bzip2 runs on one thread; lbzip2 spawns worker threads controlled with -n. Output filenames and .bz2 layout match, so you can compress with lbzip2 and decompress with bzip2 (or the reverse).
Trade-off: lbzip2 uses more CPU when all threads are busy — fine on dedicated backup hosts, worth capping with -n 2 on shared systems.
A strong answer is:
"Same .bz2 format; lbzip2 parallelizes compression and decompression with -n threads. bzip2 is single-threaded. I pick lbzip2 for large files on multi-core servers when the package is available."
How do you fix tar (child): lbzip2: Cannot exec?
tar looks for a compressor named on the command line. If lbzip2 is missing from PATH, the child process fails before any archive is written.
Check:
The step below resolves a command name with which; see the which command for PATH lookup, -a, and portable command -v alternatives.
which lbzip2Install on Ubuntu/Debian:
sudo apt install lbzip2Then retry tar --use-compress-program=lbzip2 .... You can also point tar at bzip2 if lbzip2 is not allowed on that host.
A strong answer is:
"The compressor binary is missing or not in PATH. Install the lbzip2 package or switch --use-compress-program to bzip2. I verify with which lbzip2 before long tar jobs."
Which lbzip2 flag keeps the original file?
-k (--keep) tells lbzip2 not to delete input files after compressing. -c (--stdout) also keeps inputs because output goes to stdout instead of replacing the file.
Example:
lbzip2 -k access.log
ls access.log access.log.bz2A strong answer is:
"I use -k to keep the source file after compression. -c also keeps inputs when I pipe compressed data to another command."
How do you verify a .bz2 file without extracting it?
Run lbzip2 -t archive.bz2. The -t (--test) mode decompresses in memory, checks block checksums, and discards output. Exit code 0 means the file is valid bzip2 data.
A strong answer is:
"lbzip2 -t file.bz2 — it decompresses internally and exits non-zero if the archive is corrupt. No extracted files are written."
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
lbzip2: command not found |
Package not installed | sudo apt install lbzip2 (Debian/Ubuntu) or equivalent on your distro |
tar (child): lbzip2: Cannot exec |
tar cannot find lbzip2 in PATH |
Install lbzip2 or use --use-compress-program=bzip2 |
| Compressed file larger than source | Normal for very small inputs | Skip compression for tiny files or use gzip |
| High CPU on shared host | Default thread count uses many cores | lbzip2 -n 2 ... to cap workers |
lbzip2: Can't guess original name |
Decompressing a file without a .bz2 suffix |
Rename to file.bz2 or use lbzip2 -dc and redirect stdout |
Unknown option |
Flag from another bzip2 fork | Run lbzip2 --help on the host and match this page to lbzip2 2.5 |

