Introduction to lbzip2 command
lbzip2 is a parallel bzip2 utility. bzip2 is a single-threaded, whereas lbzip2 employs multiple threads that result in better performance on multi-core systems. lbzip2 also uses the Burrows-Wheeler block-sorting text compression algorithm. The files decompressed by lbzip2 have
.bz2 extensions like bzip2. lbzip2 uses multiple threads when decompressing
.bz2 files created by standard bzip2 too.
How to install lbzip2
In most Linux systems, lbzip2 tool is not installed by default. You can use the below commands to install lbzip2 according to your Linux distribution.
To install lbzip2 on CentOS, Fedora and RHEL
$ sudo yum install lbzip2
To install lbzip2 on Ubuntu and Debian
$ sudo apt install lbzip2
Syntax to use lbzip2 command
$ lbzip2 [options] FILE
Most of the options are similar to the bzip2 command.
Different examples to use lbzip2 command
1. lbzip2 command to compress a file
You can simply specify a file name after lbzip2 command to compress that file. The original file will be replaced by the compressed version of it.
$ lbzip2 filename
--compress options can also be used to compress a file.
$ lbzip2 -z filename
$ lbzip2 --compress filename
2. lbzip2 command to compress multiple files
lbzip2 command takes multiple file names as arguments. So, you can compress multiple files with a single lbzip2 command.
$ lbzip2 file1 file2 file3
3. lbzip2 command to decompress a file
You can use
--decompress option to decompress a
$ lbzip2 -d file.bz2
$ lbzip2 --decompress file.bz2
4. Keep input files after successful compression or decompression
By default, lbzip2 command removes the input file after compression or decompression. You can use
--keep option to not remove files after any operation.
$ lbzip2 -k filename
$ lbzip2 --keep filename
As you can see, test.txt is not replaced this time.
5. Set the compression block size during compression
lbzip2 compresses large files in blocks. It can operate at various block sizes, ranging from 100k to 900k in 100k steps, and it allocates only as much memory as it needs to. The block size affects both the compression ratio achieved, and the amount of memory needed both for compression and decompression.
-9 set the compression block size to 100K to 900K, in increments of 100K. For example,
-1 will set the compression block size to 100K,
-2 will set 200K,
-3 will set 300K, and so on. It is ignored during decompression.
$ lbzip2 -1 filename
$ lbzip2 --fast filename
--fast is an alias for
--best is alias for
6. Force overwrite existing file
If you want lbzip to overwrite existing files, you have to use
$ lbzip2 -f filename
$ lbzip2 --force filename
7. Print more detailed information on progress
Normally, lbzip2 command does not print any output on the successful compression or decompression. You can view more detailed information about compression or decompression progress using
$ lbzip2 -v filename
$ lbzip2 --verbose filename
8. Write output to standard output
--stdout, lbzip2 writes output to standard output, even when FILE operands are present. When decompressing, it shows the content of a file in the output.
$ lbzip2 -c filename
$ lbzip2 --stdout filename
golinux@ubuntu-PC:~$ lbzip2 -cd test.txt.bz2
This is a test file.
9. Set the number of compressor/decompressor threads
-n option is used to set the number of compressor or decompressor threads. The number should be a positive integer.
$ lbzip2 -n NUM
golinux@ubuntu-PC:~$ lbzip2 -n 5 test.txt
10. Test decompression
--test option helps to test the decompression. It discards output instead of writing it to files or standard output.
-v can be used for verbose information.
$ lbzip2 -t filename
$ lbzip2 --test filename
This command is useful to check whether the specified file is a valid
.bz2 file or not.
For example, if you create a
.bz2 file using cat or similar commands, you will get an error message when you test that file.
This tutorial covers the most common practical examples of lbzip2 commands. We hope this tutorial helps you to understand how to use lbzip2 commands in Linux. If you have any confusion, do let us know in the comment section below.