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,還有其它的如:

Type Format Example filename
-t7z 7Z archive.7z(默認)
-tgzip GZIP archive.gzip,archive.gz
-tzip ZIP archive.zip(兼容)
-tbzip2 BZIP2 archive.bzip2
-ttar TAR tarball.tar(Unix/Linux)
-tiso ISO image.iso(可能不支持)
-tudf UDF disk.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文件,否則你執行命令的時候可能會遇到上面的錯誤。你可以從這里直接下載>>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM