unzip
圧縮と転送
書き方
unzip [-d <dir>] <archive.zip>.zip を展開しますが、`-d` を与えないと今いるディレクトリにそのままぶちまけるので、先に `-l` で最上位のフォルダーがあるかを見ます。古い Windows で作られたものは名前が化けるため `-O CP932` が要り、`-P` で渡した合言葉はシェルの履歴と ps に残ります。
よく使うオプション
| オプション | 意味 |
|---|---|
| -l | List the contents without extracting. |
| -d <dir> | Extract there instead of into the current directory. |
| -o | Overwrite existing files without asking. |
| -n | Never overwrite: skip files that already exist. |
| -j | Flatten the paths into one directory. |
| -q | Quiet, for scripts. |
| -O CP932 | Interpret 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.zipCheck whether it has a top-level folder before extracting.
unzip archive.zip -d /tmp/outExtract somewhere harmless.
unzip -O CP932 japanese.zipFixes 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