unzip
压缩与传输
用法
unzip [-d <dir>] <archive.zip>解开 .zip;不给 `-d` 就直接倒在当前目录里,所以先用 `-l` 看看包内有没有一层顶层文件夹,旧版 Windows 打的包要靠 `-O CP932` 才不乱码,而 `-P` 写在命令行里的密码会留在 shell 历史和 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` 写在命令行里的密码会留在 shell 历史和 ps 里。
Q. 怎么写?
unzip [-d <dir>] <archive.zip> —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 8 个,完整列表在 man unzip。这条命令属于压缩与传输。
相关命令
man 手册: man unzip