第 7章圧縮/伸長とアーカイブ

7.1. gz ファイルへの圧縮と伸長 【gzip、gunzip】

$ gzip [オプション] ファイル名

gzip 形式(拡張子 .gz)のファイルに圧縮/伸長する場合は gzip というコマンドを使用します。

代表的なオプションを以下に示します。

表 7-1. gzip コマンドのオプション

-dファイルを伸長します。
-f同名のファイルがあった場合でも上書きし、強制的に実行します。
-v実行結果を表示します。

例えば、カレントディレクトリに存在する拡張子が .txt のファイルをすべて圧縮します。

$ gzip -v *.txt
test1.txt:               49.6% -- replaced with test1.txt.gz
test2.txt:               47.2% -- replaced with test2.txt.gz
test3.txt:               85.3% -- replaced with test3.txt.gz
test4.txt:               64.4% -- replaced with test4.txt.gz
test5.txt:               62.9% -- replaced with test5.txt.gz

ファイルが圧縮され、.gz という拡張子が付加されます。-v オプションにより、実行結果が表示されます。

次に、圧縮したファイルをすべて伸長します。

$ gzip -dv *.gz
test1.txt.gz:            49.6% -- replaced with test1.txt
test2.txt.gz:            47.2% -- replaced with test2.txt
test3.txt.gz:            85.3% -- replaced with test3.txt
test4.txt.gz:            64.4% -- replaced with test4.txt
test5.txt.gz:            62.9% -- replaced with test5.txt

ファイルが伸長されました。

gzip 形式で圧縮されたファイル(拡張子 .gz)を伸長するには gunzip コマンドを使用することもできます。

$ gunzip -v *gz
test1.txt.gz:            49.6% -- replaced with test1.txt
test2.txt.gz:            47.2% -- replaced with test2.txt
test3.txt.gz:            85.3% -- replaced with test3.txt
test4.txt.gz:            64.4% -- replaced with test4.txt
test5.txt.gz:            62.9% -- replaced with test5.txt