7z
壓縮與傳輸
用法
7z <a|x|l> <archive.7z> [files]它把動作寫在最前面——`a` 新增、`x` 帶路徑解壓、`e` 攤平解壓、`l` 列出——能讀的遠不止 .7z,zip、tar、rar 都行,壓縮率也比多數工具高;`-o` 後面不能有空格,目錄要緊貼著寫,而想連檔名一起藏起來,得在 `-p` 之外再加 `-mhe=on`。
常用選項
| 選項 | 含義 |
|---|---|
| a | Add or create. |
| x | Extract keeping the stored directory structure. |
| e | Extract everything into one directory, flattening paths. |
| l | List the contents. |
| -o<dir> | Output directory, written with no space after -o. |
| -p<password> | Password. Add -mhe=on to encrypt the file names too. |
| -mx=9 | Maximum compression. |
| -t7z / -tzip | Choose the output format. |
範例
7z a -mx=9 backup.7z ./dataA tightly compressed archive.
7z x archive.7z -o/tmp/outExtract with the folder structure intact.
7z a -p -mhe=on secret.7z ./docsEncrypt the contents and the file names, with a prompted password.
打包和壓縮是兩件事:tar 打包,gzip 壓小,.tar.gz 是兩樣一起。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. 7z 是做什麼的?
它把動作寫在最前面——`a` 新增、`x` 帶路徑解壓、`e` 攤平解壓、`l` 列出——能讀的遠不止 .7z,zip、tar、rar 都行,壓縮率也比多數工具高;`-o` 後面不能有空格,目錄要緊貼著寫,而想連檔名一起藏起來,得在 `-p` 之外再加 `-mhe=on`。
Q. 怎麼寫?
7z <a|x|l> <archive.7z> [files] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 8 個,完整列表在 man 7z。這條命令屬於壓縮與傳輸。
相關命令
man 手冊: man 7z