lbzip2 logo

Quick start

Quick start

Using lbzip2 should be straightforward for most of users because it is fully compatible with bzip2. Additionally, lbzip2 usage is very similar to other compressors, like gzip and xz, so users of these programs should have no problems using lbzip2.

There’s a chance that lbzip2 is already installed in your system. You can check this by running:

lbzip2 -V

If lbzip2 is not installed then system shell will print something like “command not found”. Otherwise version of installed lbzip2 will be printed. The latest released version of lbzip2 is 2.5. It’s recommended to use the latest version if possible. If you can’t upgrade lbzip2 installed in your system then you can build and install a local copy.

lbzip2 is shipped with number of operating systems. It is recommended to use packaging management software of your system to install system version of lbzip2. If you can’t or don’t want to do this, you can compile lbzip2 from sources.

This document presents only basic usage of lbzip2. More advanced usage, including all available options, is described in detail in the manual. You are encouraged to see the manual if this document doesn’t give enough information.

File compression

To compress a single file you can simply run:

lbzip2 file_name

This command will replace file_name with its compressed form – file_name.bz2. The original file will be deleted upon successful compression. You can keep it by specifying --keep parameter (-k in short):

lbzip2 -k file_name

Compression of larger number of files is possible by enumerating them all in one call to lbzip2, for example:

lbzip2 file1 file2 file3

or (using shell wildcard expansion):

lbzip2 *.txt

lbzip2 doesn’t output any logging information during normal operation. Error messages are printed only on failure, but also warnings can be printed in some cases too. More verbose logging can be turned on by specifying --verbose option (-v in short):

lbzip2 -v *.txt

Verbose output includes several useful pieces information. One of them is progress estimation, which is especially useful for big files.

File decompression

To decompress files compressed with lbzip2 the following command can be used:

lbunzip2 file_name.bz2

It will cause compressed file to be replaced by it’s expanded form.

Just like in case of compression, you can specify multiple files to be decompressed. You can also use --keep and --verbose.

Pipeline processing

If no file names are given as command line arguments then lbzip2 works in filter mode. This means that lbzip2 will compress or decompress data from standard input to standard output. For example:

lbzip2 <file >file.bz2

lbzip2 works well with pipes, so you can redirect standard streams to a pipe. The following example concatenates several compressed files, sorts them and writes merged output to a single file.

lbzcat file*.bz2 | sort | lbzip2 >sorted.bz2

Usage with GNU tar

Creation of .tar.bz2 compressed archive:

tar cjf archive.tar.bz2 files-to-be-added

Extraction of .tar.bz2 compressed archive:

tar xjf archive.tar.bz2 files-to-be-extracted

To extract all files just skip the files-to-be-extracted part.

The above commands will use lbzip2 only if bzip2 is not installed or tar was configured to work with lbzip2. Otherwise you can pass an additional --use-compress-program option to tar to make it use lbzip2, for example:

tar xf archive.tar.bz2 --use-compress-program lbzip2

Testing compressed files

The following command will check it integrity of compressed files:

lbzip2 -tv *.bz2

It also shows compression ratio and space savings of each file processed.

More information

For additional information about lbzip2 usage see the manual page. You can also check frequently asked questions or contact lbzip2 maintainer directly.