unzip

圧縮と転送

書き方

unzip [-d <dir>] <archive.zip>

.zip を展開しますが、`-d` を与えないと今いるディレクトリにそのままぶちまけるので、先に `-l` で最上位のフォルダーがあるかを見ます。古い Windows で作られたものは名前が化けるため `-O CP932` が要り、`-P` で渡した合言葉はシェルの履歴と ps に残ります。

よく使うオプション

オプション意味
-lList the contents without extracting.
-d <dir>Extract there instead of into the current directory.
-oOverwrite existing files without asking.
-nNever overwrite: skip files that already exist.
-jFlatten the paths into one directory.
-qQuiet, for scripts.
-O CP932Interpret file names in a legacy code page (Debian/Ubuntu Info-ZIP only; stock macOS unzip rejects -O).
-P <password>Password on the command line, where ps and your shell history can see it.

unzip -l archive.zip

Check whether it has a top-level folder before extracting.

unzip archive.zip -d /tmp/out

Extract somewhere harmless.

unzip -O CP932 japanese.zip

Fixes mojibake from an older Windows zip, where the patched Info-ZIP is available.

まとめることと縮めることは別の仕事です。tar がまとめ、gzip が縮め、.tar.gz はその両方です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. unzip は何をしますか。

.zip を展開しますが、`-d` を与えないと今いるディレクトリにそのままぶちまけるので、先に `-l` で最上位のフォルダーがあるかを見ます。古い Windows で作られたものは名前が化けるため `-O CP932` が要り、`-P` で渡した合言葉はシェルの履歴と ps に残ります。

Q. どう打ちますか。

unzip [-d <dir>] <archive.zip> — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは8個です。全部は man unzip にあります。このコマンドは圧縮と転送の仲間です。

関連するコマンド

man ページ: man unzip