tar の -a オプションを知らなかった話

macOS (BSD) の tar には -a (--auto-compress) というオプションがあるのを知った。

c (create) のときに指定できるオプションで -f に指定したアーカイブファイル名の拡張子部分によって、どの圧縮形式を使うのかを判断してくれる。

macOS の man tar にはこんな風に書いてある。

 -a, --auto-compress
         (c mode only) Use the archive suffix to decide a set of the for-
         mat and the compressions.  As a simple example,
               tar -a -cf archive.tgz source.c source.h
         creates a new archive with restricted pax format and gzip com-
         pression,
               tar -a -cf archive.tar.bz2.uu source.c source.h
         creates a new archive with restricted pax format and bzip2 com-
         pression and uuencode compression,
               tar -a -cf archive.zip source.c source.h
         creates a new archive with zip format,
               tar -a -jcf archive.tgz source.c source.h
         ignores the ``-j'' option, and creates a new archive with
         restricted pax format and gzip compression,
               tar -a -jcf archive.xxx source.c source.h
         if it is unknown suffix or no suffix, creates a new archive with
         restricted pax format and bzip2 compression.

.tar.bz2 にするために、 -j オプションを知らずに、

tar cf - aaa bbb ccc | bzip2 -c > xxx.tar.gz2

とか書いていた私。

それが、

tar acf xxx.tar.bz2 aaa bbb ccc

で済むというのは、とても楽だと思う。 というか、.zip も作れちゃうのね。tar さん。ステキ。

でも、parallel bzip2 (pbzip2) を使いたいときには、" --use-compress-program pbzip2" かな。

tar cf xxx.tar.bz2 --use-compress-program pbzip2 aaa bbb ccc