From Gentoo Wiki
Jump to:navigation Jump to:search

Bzip2 is a high-quality, patent free file compressor using the Burrows-Wheeler algorithm. Files are typically compressed to anywhere between 10% - 15% of their original size[1] while maintaining a speed of roughly twice the speed of compression and up to six times the speed of decompression of the PPM compression family. Any machine with an ANSI C compiler should be able to support bzip2, making it a great choice for those who run systems with portable demands.


USE flags

USE flags for app-arch/bzip2 A high-quality data compressor used extensively by Gentoo Linux

split-usr Enable behavior to support maintaining /bin, /lib*, /sbin and /usr/sbin separately from /usr/bin and /usr/lib*
static-libs Build static versions of dynamic libraries as well


After adjusting USE flags:

root #emerge --ask app-arch/bzip2


Environment variables



Displays the default bzip2 arguments summary. The command line options are similar to gzip, however they aren't identical and so a little revision on bzip2's arguments go a long way. For more information, see the bzip2 man page.

A short summary of usage flags can be found below:

user $bzip2 --help
bzip2, a block-sorting file compressor.  Version 1.0.8, 13-Jul-2019.

   usage: bzip2 [flags and input files in any order]

   -h --help           print this message
   -d --decompress     force decompression
   -z --compress       force compression
   -k --keep           keep (don't delete) input files
   -f --force          overwrite existing output files
   -t --test           test compressed file integrity
   -c --stdout         output to standard out
   -q --quiet          suppress noncritical error messages
   -v --verbose        be verbose (a 2nd -v gives more)
   -L --license        display software version & license
   -V --version        display software version & license
   -s --small          use less memory (at most 2500k)
   -1 .. -9            set block size to 100k .. 900k
   --fast              alias for -1
   --best              alias for -9

   If invoked as `bzip2', default action is to compress.
              as `bunzip2',  default action is to decompress.
              as `bzcat', default action is to decompress to stdout.

   If no file names are given, bzip2 compresses or decompresses
   from standard input to standard output.  You can combine
   short flags, so `-v -4' means the same as -v4 or -4v, &c.


The default behavior of bzip2 is to compress a file when given as an argument.

user $bzip2 <file-to-compress>

If forcing a compression operation is desired, bzip2 can be invoked with the -z option:

user $bzip2 -z <file-to-compress>


If invoked as bunzip2, the default action is to decompress a given file:

user $bunzip2 <file-to-decompress>

You can also decompress to stdout:

user $bzcat <file-to-decompress>

If no arguments are given, bzip2 will compress/decompress from standard input to standard output.

Memory management

bzip2 compresses large files in blocks. The block size is proportionate to the compression ratio achieved and the total amount of memory needed for compression and decompression. Block size is read from the header of the file and can be specified manually when compressing.

You can specify the block sized used by setting -1 through to -9, which specifies block sizes of 100,000 bytes through to 900,000 bytes respectively.

When decompressing bzip2 will read this and allocate just enough space to decompress the file. Because during decompression, the block size is read from the header, the -1 to -9 flags are ignored.[2] For more information, visit the bzip2 man page.



root #emerge --ask --depclean --verbose app-arch/bzip2

See also