Bzip2 Howto David Fetter, dfetter@best.com v1.1, 5 February 1998 伊佐治 哲, isaji@mxu.meshnet.or.jp Wed Feb 25 22:36:00 1998 このドキュメントはbzip2圧縮プログラムの使い方について解説しています。 ______________________________________________________________________ 目次 1. イントロダクション 2. bzip2の入手 2.1 プレコンパイルされたbzip2バイナリを入手する 2.2 bzip2ソースの入手 2.3 マシン用のbzip2をコンパイルする 3. 単独でbzip2を使う 4. bzip2をtarと使う 4.1 設定しなくてよい: 4.2 使いやすい: 5. lessでbzip2を使う 6. emacsでbzip2を使う 7. xvでbzip2を使う 8. (訳者追加:)fd,lsでbzip2を使う 8.1 fd 8.2 ls ______________________________________________________________________ 1. イントロダクション Bzip2はデータを圧縮する"いかす"新しいアルゴリズムです。 gzipで圧縮した サイズの60-70%にファイルを圧縮します。 このドキュメントではbzip2と併用して使える2,3の共通したアプリケーション を通して話しを進めていきます。 2. bzip2の入手 Bzip2のホームページはThe UK home siteです。United Statesミラーサイトは ここです。 Red Hatのftpサイトでも見つかります。 2.1. プレコンパイルされたbzip2バイナリを入手する UK home siteを参照して下さい。Red Hatのインテルバイナリはここで す。Debian, Slackwareなどはまもなく出てきます。 2.2. bzip2ソースの入手 公式サイトから出ています(``Bzip2の入手''の章を参照して下さい)。Red Hatのものはここにあります。 (訳注:bzip2 ホームページ、http://www.muraroa.demon.co.uk/) 2.3. マシン用のbzip2をコンパイルする gcc 2.7.2.3を持っているなら CFLAGS = -O3 -fomit-frame-pointer -funroll-loops この行で-O3を外して CFLAGS = -fomit-frame-pointer -funroll-loops に変更しておいて下さい。 このあとmakeしてREADMEで書かれているようにインストールします。 3. 単独でbzip2を使う マニュアルページを読んで下さい :)。 4. bzip2をtarと使う 基本的に2つの方法があります: 4.1. 設定しなくてよい: この方法なら何も設定しなくてすみます。bzip2したtarアーカイ ブfoo.tar.bz2を un-tarするにはカレントディレクトリで、 /path/to/bzip2 -cd foo.tar.bz2 | tar xf - とします。これで動作しますが、いちいち入力するのは面倒(PITA)です。 4.2. 使いやすい: 以下のパッチをGNU tar 1.12を当ててコンパイル/インストールして下さい。 これでよいです。tarとbzip2が("which tar"、"which bzip2"と実行して) $PATHにあるかどうか確認しておきます。ファイルを展開するには tar xyf foo.tar.bz2 とします。 新しいアーカイブを作る時も同じようにして tar cyf foo.tar.bz2 file1 file2 file3...directory1 directory2... とします。 以下はパッチです :) (訳注:patch -p1 < tar.c.diffとしてあてて下さい) ______________________________________________________________________ *** tar.c.orig Sat Feb 28 14:55:45 1998 --- tar.c Sat Feb 28 15:01:54 1998 *************** *** 16,21 **** --- 16,24 ---- with this program; if not, write to the Free Software Foundation, Inc., 59 Place - Suite 330, Boston, MA 02111-1307, USA. */ + /* Feb 2 98: patched by David Fetter to use bzip2 as a + filter (option -y) */ + #include "system.h" #include *************** *** 196,201 **** --- 199,206 ---- {"block-number", no_argument, NULL, 'R'}, {"block-size", required_argument, NULL, OBSOLETE_BLOCKING_FACTOR}, {"blocking-factor", required_argument, NULL, 'b'}, + {"bzip2", required_argument, NULL, 'y'}, + {"bunzip2", required_argument, NULL, 'y'}, {"catenate", no_argument, NULL, 'A'}, {"checkpoint", no_argument, &checkpoint_option, 1}, {"compare", no_argument, NULL, 'd'}, *************** *** 372,377 **** --- 377,383 ---- PATTERN at list/extract time, a globbing PATTERN\ n\ -o, --old-archive, --portability write a V7 format archive\n\ --posix write a POSIX conformant archive\n\ + -y, --bzip2, --bunzip2 filter the archive through bzip2\n\ -z, --gzip, --ungzip filter the archive through gzip\n\ -Z, --compress, --uncompress filter the archive through compress\n\ --use-compress-program=PROG filter through PROG (must accept -d)\n"), *************** *** 448,455 **** Y per-block gzip compression */ #define OPTION_STRING \ ! "-01234567ABC:F:GK:L:MN:OPRST:UV:WX:Zb:cdf:g:hiklmoprstuvwxz" ! static void set_subcommand_option (enum subcommand subcommand) { --- 454,460 ---- Y per-block gzip compression */ #define OPTION_STRING \ ! "-01234567ABC:F:GK:L:MN:OPRST:UV:WX:Zb:cdf:g:hiklmoprstuvwxyz" static void set_subcommand_option (enum subcommand subcommand) { *************** *** 806,811 **** --- 811,820 ---- exclude_option = 1; add_exclude_file (optarg); break; + + case 'y': + set_use_compress_program_option ("bzip2"); + break; case 'z': set_use_compress_program_option ("gzip"); ______________________________________________________________________ 5. lessでbzip2を使う bzip2ファイルをすぐに展開するために、例えばはじめにbunzip2を使わず "less"を使うために、"lesspipe.sh"を作ります(lessのmanページ参照): ______________________________________________________________________ #!/bin/sh # This is a preprocessor for 'less'. It is used when this environment # variable is set: LESSOPEN="|lesspipe.sh %s" case "$1" in *.tar) tar tvvf $1 2>/dev/null ;; # View contents of .tar and .tgz files *.tgz) tar tzvvf $1 2>/dev/null ;; *.tar.gz) tar tzvvf $1 2>/dev/null ;; *.tar.Z) tar tzvvf $1 2>/dev/null ;; *.tar.z) tar tzvvf $1 2>/dev/null ;; *.bz2) bzip2 -dc $1 2>/dev/null ;; # View compressed files correctly *.Z) gzip -dc $1 2>/dev/null ;; *.z) gzip -dc $1 2>/dev/null ;; *.gz) gzip -dc $1 2>/dev/null ;; *.zip) unzip -l $1 2>/dev/null ;; *.1|*.2|*.3|*.4|*.5|*.6|*.7|*.8|*.9|*.n|*.man) FILE=`file -L $1` ; # groff src FILE=`echo $FILE | cut -d ' ' -f 2` if [ "$FILE" = "troff" ]; then groff -s -p -t -e -Tascii -mandoc $1 fi ;; *) cat $1 2>/dev/null ;; # *) FILE=`file -L $1` ; # Check to see if binary, if so -- view with 'strings' # FILE1=`echo $FILE | cut -d ' ' -f 2` # FILE2=`echo $FILE | cut -d ' ' -f 3` # if [ "$FILE1" = "Linux/i386" -o "$FILE2" = "Linux/i386" \ # -o "$FILE1" = "ELF" -o "$FILE2" = "ELF" ]; then # strings $1 # fi ;; esac ______________________________________________________________________ (訳注:環境変数LESSOPENを設定しておきます) 6. emacsでbzip2を使う 著者はjka-compr.elに当てる以下のパッチを書きました。 auto-compression-modeにbzip2を追加するものです。 免責事項:emacs-20.2でテストしただけですが、他のバージョンで動作しない ということはないと思います 1. emacs-20.2/lispソースディレクトリに移動します(untarした場所がどこで あれ)。 2. 下記のjka-compr.el.diffパッチファイルを置きます(それと同じ名前の ファイルはありません ;)。 3. patch < jka-compr.el.diff と実行します。 4. emacsを立ち上げて M-x byte-compile-file jka-compr.el とします。 5. emascを終了します。 6. バグがあったときのためにオリジナルのjka-compr.elcを安全な場所に移動 しておきます。 7. 新しいjka-compr.elcと置き換えます。 8. Have fun! ______________________________________________________________________ --- jka-compr.el Sat Jul 26 17:02:39 1997 +++ jka-compr.el.new Thu Feb 5 17:44:35 1998 @@ -44,7 +44,7 @@ ;; The variable, jka-compr-compression-info-list can be used to ;; customize jka-compr to work with other compression programs. ;; The default value of this variable allows jka-compr to work with -;; Unix compress and gzip. +;; Unix compress and gzip. David Fetter added bzip2 support :) ;; ;; If you are concerned about the stderr output of gzip and other ;; compression/decompression programs showing up in your buffers, you @@ -121,7 +121,9 @@ ;;; I have this defined so that .Z files are assumed to be in unix -;;; compress format; and .gz files, in gzip format. +;;; compress format; and .gz files, in gzip format, and .bz2 files, +;;; in the snappy new bzip2 format from http://www.muraroa.demon.co.uk. +;;; Keep up the good work, people! (defcustom jka-compr-compression-info-list ;;[regexp ;; compr-message compr-prog compr-args @@ -131,6 +133,10 @@ "compressing" "compress" ("-c") "uncompressing" "uncompress" ("-c") nil t] + ["\\.bz2\\'" + "bzip2ing" "bzip2" ("") + "bunzip2ing" "bzip2" ("-d") + nil nil] ["\\.tgz\\'" "zipping" "gzip" ("-c" "-q") "unzipping" "gzip" ("-c" "-q" "-d") ______________________________________________________________________ 7. xvでbzip2を使う xvでbzip2ファイルの自動展開(auto-decompress)をするパッチを使って動作さ せています。compressやgzipで行える方法についてだれか助けてくれません か? 8. (訳者追加:)fd,lsでbzip2を使う 8.1. fd fdですでに設定されているgzip'd tarアーカイブと同じです。ソースを変更す る場合は ______________________________________________________________________ --- orig/archive.c Thu Feb 26 06:33:27 1998 +++ archive.c Thu Feb 26 04:19:35 1998 @@ -117,6 +117,7 @@ {" ^.*\\.tar$", "tar tvf", PM_TAR}, {" ^.*\\.tar\\.Z$", "zcat %C | tar tvf -", PM_TAR}, {" ^.*\\.tar\\.gz$", "gzip -cd %C | tar tvf -", PM_TAR}, + {" ^.*\\.tar\\.bz2$", "bzip2 -cd %C | tar tvf -", PM_TAR}, {NULL, NULL, 255, 0, "", "", "", "", 1} }; archivetable archivelist[MAXARCHIVETABLE] = { @@ -130,8 +131,6 @@ "zcat %C | tar xf - %TA"}, {" ^.*\\.tar\\.gz$", "tar cf %X %T; gzip %X", "gzip -cd %C | tar xf - %TA"}, - {" ^.*\\.tar\\.bz2$", "tar cf %X %T; bzip2 %X", - "bzip2 -cd %C | tar xf - %TA"}, {NULL, NULL, NULL} }; ______________________________________________________________________ をfdソース展開ディレクトリでpatch -p1 < archive.diffとあてて (あるいは 手で直接変更して)、makeします。 また~/.fdrcで設定する場合は、# launcher definitionで ______________________________________________________________________ launch ".tar.bz2"\ "tar tvfy" 0,0:1,2-'/',2'/',3,4-'-',4'-'-'-',4[9],5,6 ______________________________________________________________________ と追加するだけです(# examples for GNU tar >=1.12)。同様に# archiver definitionに ______________________________________________________________________ arch ".tar.bz2" "tar cf %X %T; bzip2 %X" "bzip2 -cd %C|tar xf - %TA" ______________________________________________________________________ も追加しておきます。gzipと同じなのでgzip時の設定が、名前を変えるだけで そのまま使えます。簡単ですね。 ``lessと使う''章lesspipe.sh ファイルに ______________________________________________________________________ *.tar.bz2) tar tyvvf $1 2>/dev/null ;; ______________________________________________________________________ も追加します。tarでgzip用のzオプションがあるのと同じようにbzip2用オプ ションyをtarに追加しておいて下さい (``bzip2をtarと使う''章)。 8.2. ls xterm(kterm)でのアーカイブファイル色に追加することについては JFから和 訳も出ている「Colour-ls」"3. ls のカラー設定法"を参考にして下さい。 例えば、/etc/DIR_COLORSファイルを以下のように変更します (一部引用)。 ______________________________________________________________________ .Z 01;31 .gz 01;31 .bz2 01;31 <--- ここ .jpg 01;35 # image formats .gif 01;35 .bmp 01;35 ______________________________________________________________________