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