7z压缩与解压命令

在写很多工具的时候,可能会用到7z命令来进行压缩与解压操作。这里记录二个比较常用的操作:压缩、解压。

 

在dos窗口下输入7z命令,会显示7z的使用参数详情:

7-Zip 9.10 beta  Copyright (c) 1999-2009 Igor Pavlov  2009-12-22

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

<Commands>
  a: Add files to archive
  b: Benchmark
  d: Delete files from archive
  e: Extract files from archive (without using directory names)
  l: List contents of archive
  t: Test integrity of archive
  u: Update files to archive
  x: eXtract files with full paths
<Switches>
  -ai[r[-|0]]{@listfile|!wildcard}: Include archives
  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
  -bd: Disable percentage indicator
  -i[r[-|0]]{@listfile|!wildcard}: Include filenames
  -m{Parameters}: set compression Method
  -o{Directory}: set Output directory
  -p{Password}: set Password
  -r[-|0]: Recurse subdirectories
  -scs{UTF-8 | WIN | DOS}: set charset for list files
  -sfx[{name}]: Create SFX archive
  -si[{name}]: read data from stdin
  -slt: show technical information for l (List) command
  -so: write data to stdout
  -ssc[-]: set sensitive case mode
  -ssw: compress shared files
  -t{Type}: Set type of archive
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
  -v{Size}[b|k|m|g]: Create volumes
  -w[{path}]: assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
  -y: assume Yes on all queries

 

必选参数:最常用的命令有a(压缩)、x(解压),其它的命令诸如删除,解压出来不保留目录结构这种,一般情况下都用不到。

可选参数:最常用的就是-t{Type}

Type默认值为7z,还有其它的如:

TypeFormatExample filename
-t7z7Zarchive.7z(默认)
-tgzipGZIParchive.gzip,archive.gz
-tzipZIParchive.zip(兼容)
-tbzip2BZIP2archive.bzip2
-ttarTARtarball.tar(Unix/Linux)
-tisoISOimage.iso(可能不支持)
-tudfUDFdisk.udf

常用的就是-t{Type}以及-r、-o、-y

 

解压命令:7z x -tzip -y xx-13.zip (解压到当前目录,如需改变输出目录,需要附加使用-o)

压缩命令:7z a -tzip -r xx.zip a\* b\*

将目录a、目录b,压缩成一个xx.zip

 

更多参数的详情,可以参考这里:http://www.dotnetperls.com/7-zip-examples

 

在Windows的64位操作系统下,除需要7z.exe外,还需要7z.dll,我将他们打包为一个zip文件,否则你执行命令的时候可能会遇到上面的错误。你可以从这里直接下载>>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值