7zip在dos命令行用法总结

所属分类: 脚本专栏 / DOS/BAT 阅读数: 1161
收藏 0 赞 0 分享

7zip功能很强大,你只要两个文件,7z.exe以及7z.dll就可以使用命令行工作了。

安装完7zip软件后,在其安装目录下找到7z.exe和7z.dll两个文件,将其复制到C:\Windows\System32便可以在DOS直接应用。

常用方式:

-o (set Output directory) switch
Specifies a destination directory where files are to be extracted.

This switch can be used only with extraction commands.

Syntax-o{dir_path} {dir_path} This is the destination directory path. It's not required to end with a backslash. If you specify * in {dir_path}, 7-Zip substitutes that * character to archive name.
Example 7z x archive.zip -oc:\Doc
extracts all files from the archive.zip archive to the c:\Doc directory.

7z x *.zip -o*
extracts all *.zip archives to subfolders with names of these archives.

Usage: 7za <command> [<switches>...] <archive_name> [<file_names>...]
[<@listfiles...>]

1. "a",添加文件
7z a -t7z files.7z *.txt

2. "d", 删除文件
7z d archive.zip *.bak -r
从zip文件中删除所有的*.bak文件

3. "e", 解压缩
7z e archive.zip

4. "l", 列出文件
7z l archive.zip

5. "t", 测试完整性
7z t archive.zip *.doc -r

6. "u", 更新
7z u archive.zip *.d

7. "x", 与e相同,但保留全路径

8. "m", 指定优化级别
Compression switch: -mx0
What it means: Don't compress at all.
Is called "copy mode."

Compression switch: -mx1
What it means: Very low compression.
It is called "fastest" mode.

Compression switch: -mx3
What it means: Fast compression mode.
Will set various parameters automatically.

Compression switch: -mx5
What it means: Same as above, but "normal."

Compression switch: -mx7
What it means: "maximum" compression.

Compression switch: -mx9
What it means: "ultra" compression.
(You probably want to use this.)

9. "-m"选项:
Switch: -mfb
Function: Specifies # of fast bytes.
Sometimes help with very "sparse" files.
Don't bother.

Switch: -mpass
Function: Number of passes for deflate compression.
Don't bother with this.
Automatically set with levels.

Switch: -md
Function: Specifies dictionary size.
Automatically set, so don't bother.

Switch: -mmt
Function: Enable multithreading.
Use if: you have quad-core and a really huge archive.
Specify "on" or "off".
This may be enabled by default; check the help file.

10. "-t"选项
指定压缩文件类型
Type switch: -t7z
Format: 7Z
Example filename: archive.7z (default option)

Type switch: -tgzip
Format: GZIP
Example filename: archive.gzip
archive.gz

Type switch: -tzip
Format: ZIP
Example filename: archive.zip (very compatible)

Type switch: -tbzip2
Format: BZIP2
Example filename: archive.bzip2

Type switch: -ttar
Format: TAR
Example filename: tarball.tar (UNIX and Linux)

Type switch: -tiso
Format: ISO
Example filename: image.iso

Type switch: -tudf
Format: UDF
Example filename: disk.udf

7z a -tiso archive.iso
7z a -tudf archive.udf

7z: executable name
a: add to archive
-tiso or -tudf: format of archive to create
archive.iso or archive.udf: name of archive to create

10. 硬压缩
Switch: -ms=on
Function: Enable solid mode.
This is the default so you won't often need this.

Switch: -ms=off
Function: Disable solid mode.
This is useful when you need to update individual files.
Will reduce compression ratios normally.

11. "-p"设定密码
7z a pw.7z *.txt -pSECRET

12. 其它选项:
Switch: -ssc
Function: Specify case-sensitive mode.
Useful for going between Linux and Windows.
Default: -ssc- on Windows (insensitive)
Default: -scc on Linux (sensitive)


Switch: -ssw
Function: Compress locked files.
Use if: you have problems with opening files.

Switch: -w
Function: Set working directory.
Use when you want to specify temp folders.

Switch: -aoa
Overwrite all destination files.

Switch: -aos
Skip over existing files without overwriting.
Use this for files where the earliest version is most important.

Switch: -aou
Avoid name collisions.
New files extracted will have a number appending to their names.
(You will have to deal with them later.)

Switch: -aot
Rename existing files.
This will not rename the new files, just the old ones already there.
Use when the new files are more important.

7z x test.zip -aoa

7z: use the 7-zip executable
x: use the extract command
test.zip: extract files from this archive

-aoa: overwrite all existing files. risky!

更多精彩内容其他人还在看

for 语句从入门到精通

在批处理中,for是最为强大的命令语句,它的出现,使得解析文本内容、遍历文件路径、数值递增/递减等操作成为可能
收藏 0 赞 0 分享

dos 目录跳转 cd

当我们需要处理不同路径下的文件的时候,很可能需要切换目录,这个时候,可以考虑使用目录跳转命令cd。
收藏 0 赞 0 分享

tree 以树形格式罗列文件

tree ,在英语中的基本含义是“树”,在cmd中,tree命令的功能是以树形格式罗列文件。
收藏 0 赞 0 分享

dos 内容重定向

当我们在cmd窗口中查询某条命令的帮助信息的时候,帮助信息是显示在命令行窗口中的,命令行窗口关闭后,这些帮助信息就看不到了,如果下次还想看,又得在命令行窗口中输入查询命令,比较繁琐。
收藏 0 赞 0 分享

执行批处理bat程序中的条件处理

一直用bat实现部分功能,对于我们仍需要控制是否满意我们的要求,下面是if帮助文档,方便查询
收藏 0 赞 0 分享

不错的批处理脚本 第一部分

非常不错的批处理脚本代码,功能比较多,用到了,很多的批处理机器
收藏 0 赞 0 分享

不错的批处理脚本实例代码 第二部分

不错的批处脚本实例代码,用到了批处理中的很多技巧与知识点,不懂得可以逐一查找相关资料
收藏 0 赞 0 分享

开机更新桌面主题的批处理代码

更新桌面主题的批处理代码
收藏 0 赞 0 分享

非常好的for 教程, 当时我就是看这个学习for 的第1/2页

批处理for命令详解 FOR这条命令基本上都被用来处理文本,但还有其他一些好用的功能! 看看他的基本格式(这里我引用的是批处理中的格式,直接在命令行只需要一个%号)
收藏 0 赞 0 分享

批处理的"循环"效果脚本

曾经在回答一个问题时 无意中想到的方法 今天又看到类似的问题 个人认为是非常实用的 于是 想把这种方法推荐给大家
收藏 0 赞 0 分享
查看更多