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