ZIP形式のファイルを展開・圧縮するには

 ZIP形式は、Windowsでよく使われる圧縮方式だ。特に、海外ではファイルをZIP形式で配布するケースが多い。

 LinuxでZIP形式のファイルを展開するにはunzipコマンドを使用する。例えば、foo.zipというファイルを展開するには以下のように行う。

$ unzip foo.zip
Archive: foo.zip
  inflating: xxxxx.yyy
  inflating: yyyyy.zzz
(省略)

 また、ZIP形式に含まれるファイルの一覧を表示するには-lオプションを付けてunzipコマンドを実行する。

$ unzip -l tmp.zip
Archive:  tmp.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
  1205839  06-13-01 23:30   010601.tif
  1147425  06-13-01 16:56   010602.tif
  1147425  06-13-01 16:59   010603.tif
  1106511  06-14-01 00:25   01060a.tif
 --------                   -------
  4607200                   4 files

 ファイルを圧縮するときはzipコマンドを使用する。例えば、カレントディレクトリにある拡張子が.tifのファイルをtmp.zipというファイルに圧縮するには、以下のコマンドを実行する。

$ zip tmp.zip *.tif
  adding: 010601.tif (deflated 76%)
  adding: 010602.tif (deflated 82%)
  adding: 010603.tif (deflated 91%)
  adding: 01060a.tif (deflated 88%)
  adding: lynx.tif (deflated 98%)

 すでに存在するZIP形式のファイルに新たにファイルを追加する場合も、同様にすればいい。例えば、上記で作成したtmp.zipに、カレントディレクトリにある拡張子が.txtのファイルを追加するには、以下のコマンドを実行する。

$ zip tmp.zip *.txt
  adding: a.txt (stored 0%)
  adding: b.txt (stored 0%)
  adding: c.txt (stored 0%)
  adding: d.txt (deflated 47%)

 ZIP形式のファイルから特定のファイルを削除するには、-dオプションを使用する。例えばtmp.zipから拡張子が.txtのファイルを削除するには、以下のコマンドを実行する。

$ zip tmp.zip -d *.txt
deleting: a.txt
deleting: b.txt
deleting: c.txt
deleting: d.txt