10 lbzip2 command examples in Linux [Cheat Sheet]

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.

Advertisement

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

Sample Output:

lbzip2 command to compress a file

-z or --compress options can also be used to compress a file.

Advertisement
$ lbzip2 -z filename

OR

$ 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

Sample Output:

lbzip2 command to compress multiple files

 

3. lbzip2 command to decompress a file

You can use -d or --decompress option to decompress a .bz2 file.

$ lbzip2 -d file.bz2

OR

$ lbzip2 --decompress file.bz2

Sample Output:

Advertisement

lbzip2 command to decompress a file

 

4. Keep input files after successful compression or decompression

By default, lbzip2 command removes the input file after compression or decompression. You can use -k or --keep option to not remove files after any operation.

$ lbzip2 -k filename

OR

$ lbzip2 --keep filename

Sample Output:

As you can see, test.txt is not replaced this time.

lbzip2 command to keep original file

 

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.

The options -1 to -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.

Advertisement
$ lbzip2 -1 filename

OR

$ lbzip2 --fast filename

--fast is an alias for -1 whereas --best is alias for -9.

 

6. Force overwrite existing file

If you want lbzip to overwrite existing files, you have to use -f or --force option.

$ lbzip2 -f filename

OR

$ lbzip2 --force filename

Sample Output:

lbzip2 command to overwrite existing file

 

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 -v or --verbose option.

Advertisement
$ lbzip2 -v filename

OR

$ lbzip2 --verbose filename

Sample Output:

lbzip2 command to display more information

 

8. Write output to standard output

With option -c or --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

OR

$ lbzip2 --stdout filename

Sample Output:

golinux@ubuntu-PC:~$ lbzip2 -cd test.txt.bz2
This is a test file.

 

9. Set the number of compressor/decompressor threads

The -n option is used to set the number of compressor or decompressor threads. The number should be a positive integer.

Advertisement
$ lbzip2 -n NUM

Sample Output:

golinux@ubuntu-PC:~$ lbzip2 -n 5 test.txt

 

10. Test decompression

The -t or --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

OR

$ lbzip2 --test filename

Sample Output:

lbzip2 command to test decompression

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.

Advertisement

lbzip2 command to test integrity of decompressed file

 

Conclusion

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.

 

What’s Next

10+ bzip2 command examples in Linux [Cheat Sheet]
10+ xz command examples in Linux [Cheat Sheet]

 

Further Reading

man page for lbzip2 command

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment

X