bzip2 とは、ファイルをBZIP2形式で圧縮するLinux/Unixコマンドである。gzip コマンドと比べて圧縮効率が高いのが特徴である。bzip2 と bunzip2 は実質的に同じプログラムであり、bzip2 コマンドで解凍したり、bunzip2 コマンドで圧縮することもできる。
本サイトのすべてを tar コマンドでまとめたファイルを例に、圧縮率の違いを以下に示す。
| 圧縮方法 | ファイルサイズ |
|---|---|
segakuin.com.tar (非圧縮) |
74127360 |
gzip -6 segakuin.com.tar |
54639263 |
gzip -1 segakuin.com.tar |
55798062 |
gzip -9 segakuin.com.tar |
54582925 |
bzip2 egakuin.com.tar |
54224356 |
gzip -9 より bzip2 コマンドで圧縮した方が圧縮率が良い。
bzip2 [-cdfkqstvzVL123456789] [filename]...
bzip2 [-h|--help]
圧縮するファイルのパスを引数に指定する。
$ bzip2 example.tar
複数のファイルを引数に指定できる。
$ bzip2 file1 file2 file3
以下に示すオプションをコマンドに指定できる。
$ bzip2 -d example.txt.bz2
$ bzip2 --decompress example.txt.bz2
$ bzip2 -z example.txt
ファイルの圧縮は bzip2 コマンドのデフォルトの動作であるため、オプションを省略できる。
$ bzip2 example.txt
$ bzip2 --compress example.txt
ファイルの圧縮は bzip2 コマンドのデフォルトの動作であるため、オプションを省略できる。
$ bzip2 --compress example.txt
$ bzip2 example.txt
bzip2: Output file example.txt.bz2 already exists.
$ bzip2 -f example.txt
$ bzip2 example.txt
bzip2: Output file example.txt.bz2 already exists.
$ bzip2 --force example.txt
$ bzip2 -k example.txt
$ bzip2 --keep example.txt
$ bzip2 -V example.txt
$ bzip2 --verbos example.txt
$ bzip2 -h
$ bzip2 --help
$ bzip2 -V
$ bzip2 --version