LoginSignup
67
50

More than 5 years have passed since last update.

マルチコアでgzファイルの圧縮解凍ができるpigzの使い方

Last updated at Posted at 2015-09-22

Linux標準の gzip や gunzip だとシングルでの処理(1 CPUだけ)になってしまうので、gzファイルを高速に解凍(圧縮)したい!! という時に残念な気持ちになります。

そこでその残念な気持ちを救うのが pigz というLinuxソフト。
マルチコアを活かして並列処理で圧縮・解凍ができるので、CPUをたくさん積んでいる環境だと爆速に処理することができるようになります。

pigz-howto-install.png

インストール方法

pigzは外部リポジトリのEPELリポジトリを利用してyumインストールすることも可能ですが、僕的にはサクッと簡単安心?なソースインストールをおすすめしています。

まずはインストールディレクトリに移動してソースパッケージをダウンロードしておきます。

$ cd /usr/local/src/
$ wget http://zlib.net/pigz/pigz-2.4.tar.gz

念の為に必要なパッケージを確認して無ければインストール。

# rpm -qa | grep zlib-devel
# yum install zlib-devel

zlib-devel が入っていないと下記のようなエラーが出ますので。

pigz.c:390:70: error: zlib.h: そのようなファイルやディレクトリはありません
pigz.c:397:4: error: #error "Need zlib version 1.2.3 or later"

続いてダウンロードしたソースパッケージを解凍してインストール。
『インストール』といっても make install はせずに、直接実行ファイルをパスの通ったディレクトリへコピーします。

$ tar -xzf pigz-2.4.tar.gz
$ cd pigz-2.4
$ make
$ cp -p pigz unpigz /usr/local/bin/

使い方

pigz の使い方は gzip コマンドや gunzip コマンドとほぼ同じです。
例えば圧縮するときは下記のようにします。

$ pigz -c Accesslog.txt > Accesslog.txt.gz

逆に、解凍するときは unpigz を使います。

$ unpigz -c Accesslog.txt.gz > Accesslog.txt

ちなみに tar と組み合わせて利用することも可能。
tarコマンドの --use-compress-prog オプションを利用します。

追記:2015-12-28
一部環境によっては -z オプションが不要な場合もあるようですので、ご自身の環境でご確認ください。

$ tar -czf HOGEHOGE.tgz --use-compress-prog=pigz HOGEHOGE

オプション

使えるオプションとしては下記の通り。(端折るな)
普段使うことがあるとすれば -c の標準出力ぐらいでしょうか。

オプション 説明
-0 to -9, -11 Compression level (11 is much slower, a few % better)
--fast, --best Compression levels 1 and 9 respectively
-b, --blocksize mmm Set compression block size to mmmK (default 128K)
-c, --stdout Write all processed output to stdout (won't delete)
-d, --decompress Decompress the compressed input
-f, --force Force overwrite, compress .gz, links, and to terminal
-F --first Do iterations first, before block split for -11
-h, --help Display a help screen and quit
-i, --independent Compress blocks independently for damage recovery
-I, --iterations n Number of iterations for -11 optimization
-k, --keep Do not delete original file after processing
-K, --zip Compress to PKWare zip (.zip) single entry format
-l, --list List the contents of the compressed input
-L, --license Display the pigz license and quit
-M, --maxsplits n Maximum number of split blocks for -11
-n, --no-name Do not store or restore file name in/from header
-N, --name Store/restore file name and mod time in/from header
-O --oneblock Do not split into smaller blocks for -11
-p, --processes n Allow up to n compression threads (default is the number of online processors, or 8 if unknown)
-q, --quiet Print no messages, even on error
-r, --recursive Process the contents of all subdirectories
-R, --rsyncable Input-determined block locations for rsync
-S, --suffix .sss Use suffix .sss instead of .gz (for compression)
-t, --test Test the integrity of the compressed input
-T, --no-time Do not store or restore mod time in/from header
-v, --verbose Provide more verbose output
-V --version Show the version of pigz
-z, --zlib Compress to zlib (.zz) instead of gzip format
67
50
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
67
50