Bash unzip コマンド
1. unzip コマンドの使用方法
unzip コマンドは、ZIP アーカイブから圧縮されたファイルを展開(解凍)するために使用されます。
1.1 基本的な使い方
ZIP アーカイブからファイルを展開するには、unzip archive.zip という構文を使用します。
実行例:
unzip archive.zip
Archive: archive.zip
inflating: file1
inflating: file22. Unzip オプションの概要
unzip コマンドで使用される主なオプションは以下の通りです:
-l- アーカイブ内のファイルをリスト表示する-t- 圧縮されたアーカイブファイルの整合性をテストする-d- 指定した別のディレクトリにファイルを展開する-o- 確認プロンプトを表示せずに既存のファイルを上書きする-x- 展開対象から特定のファイルを除外する
2.1 オプション:-l (List)
-l オプションを使用すると、ファイルを展開せずに ZIP アーカイブ内の全ファイルを一覧表示できます。
実行例:ファイルのリリスト表示
unzip -l archive.zip
Length Date Time Name
--------- ---------- ----- ----
1234 2025-04-10 12:00 file1
5678 2025-04-10 12:00 file2
--------- -------
2 files2.2 オプション:-t (Test)
-t オプションは、ZIP アーカイブ内のファイルが壊れていないか、整合性をチェックします。
実行例:アーカイブのテスト
unzip -t archive.zip
Archive: archive.zip
testing: file1 OK
testing: file2 OK
No errors detected in compressed data of archive.zip2.3 オプション:-d (Extract to Directory)
-d オプションを使用すると、指定したディレクトリにファイルを展開できます。
実行例:ディレクトリを指定して展開
unzip -d /path/to/extract/ archive.zip
Archive: archive.zip
inflating: /path/to/extract/file1
inflating: /path/to/extract/file22.4 オプション:-o (Overwrite)
-o オプションを指定すると、展開先に同名のファイルが存在する場合でも、プロンプトで確認せずに強制的に上書きします。
実行例:ファイルの上書き
unzip -o archive.zip
Archive: archive.zip
replacing: file1
replacing: file22.5 オプション:-x (Exclude)
-x オプションを使用すると、アーカイブから特定のファイルを除外して展開できます。
実行例:ファイルの除外
unzip archive.zip -x file1
Archive: archive.zip
inflating: file2