配置
- 下载安装7z
- 配置环境变量
- win键按下,搜索
env
,打开编辑环境变量,选择环境变量 - 在系统变量下的
path
中添加你的7zip安装位置,如C:\Program Files\7-Zip\
- 一路OK确认,关闭窗口
- win键按下,搜索
- 检查可用性
- 打开cmd,输入
7z
命令,查看是否可用
- 打开cmd,输入
文档
这里只列了一部分,不想看英语的请忽略吧~
7z -h
Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
<Commands>
a : Add files to archive
b : Benchmark
d : Delete files from archive
e : Extract files from archive (without using directory names)
h : Calculate hash values for files
i : Show information about supported formats
l : List contents of archive
rn : Rename files in archive
t : Test integrity of archive
u : Update files to archive
x : eXtract files with full paths
<Switches>
...
压缩
7z a -t[format] archive_name file_name
- 参数
a
表示【加】进压缩包 - -t[format] 表示压缩包格式,自己指定,如
-tzip
为 zip 压缩包 - archive_name 压缩包名字
- file_name 文件名,带扩展名,可以一个一个罗列出来,也可以用通配符,如
*.txt
匹配所有txt文件*.*
匹配所有文件
举例
将当前目录下所有 docx 文件打包压缩,压缩包名为 archive_name.zip
7z a -tzip archive_name.zip *.docx
解压
- 参数有两种:一个是e,一个是x
- 区别:e解压出来的没有文件夹结构,x解压出来的有文件夹结构
- 一般都用 x
下面说明 x
的语法
7z x -o[output_dir] archive_name
- -o[output_dir] 输出文件夹,举例:-otest 表示当前目录下的 test 文件夹下,不写就是当前目录
- 注意输出 -o 和文件夹名称要连着写,中间没有空格
举例
解压缩archive.zip包到当前目录下的source_file文件夹下
7z x -osource_file archive.zip
查看压缩包有什么文件
l
表示列出所有文件 (是英文字母 L)
7z l test.zip