7Z壓縮命令行詳解

Usage: 7za <command> [<switches>...] <archive_name> [<file_names>...]br/>[<@listfiles...>]
<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>
-- : Stop switches parsing
-ai[r[-|0]]{@listfile|!wildcard} : Include archives
-ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
-ao{a|s|t|u} : set Overwrite mode
-an : disable archive_name field
-bb[0-3] : set output log level
-bd : disable progress indicator
-bs{o|e|p}{0|1|2} : set output stream for output/error/progress line
-bt : show execution time statistics
-i[r[-|0]]{@listfile|!wildcard} : Include filenames
-m{Parameters} : set compression Method
-mmt[N] : set number of CPU threads
-o{Directory} : set Output directory
-p{Password} : set Password
-r[-|0] : Recurse subdirectories
-sa{a|e|s} : set Archive name mode
-scc{UTF-8|WIN|DOS} : set charset for for console input/output
-scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files
-scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands
-sdel : delete files after compression
-seml[.] : send archive by email
-sfx[{name}] : Create SFX archive
-si[{name}] : read data from stdin
-slp : set Large Pages mode
-slt : show technical information for l (List) command
-snh : store hard links as links
-snl : store symbolic links as links
-sni : store NT security information
-sns[-] : store NTFS alternate streams
-so : write data to stdout
-spd : disable wildcard matching for file names
-spe : eliminate duplication of root folder for extract command
-spf : use fully qualified file paths
-ssc[-] : set sensitive case mode
-ssw : compress shared files
-stl : set archive timestamp from the most recently modified file
-stm{HexMask} : set CPU thread affinity mask (hexadecimal number)
-stx{Type} : exclude archive type
-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

語法格式:(詳細情況見7-zip幫助文件,看得頭暈可以跳過,用到再學) 
7z <command> [<switch>...] <base_archive_name> [<arguments>...] 
7z.exe的每個命令都有不同的參數<switch>,請看幫助文件 
<base_archive_name>爲壓縮包名稱 
<arguments>爲文件名稱,支持通配符或文件列表 
a: 添加文件的壓縮包,或者創建新的壓縮包。 
d: 從壓縮包中刪除文件。 
e: 從壓縮包中提取。 
t: 測試壓縮包的是否出錯。 
u: 更新壓縮包中的文件。 
其中,7z是至命令行壓縮解壓程序7z.exe,<command>是7z.exe包含的命令,列舉如下: 
a: Adds files to archive. 添加至壓縮包 
a命令可用參數: 
-i (Include) 
-m (Method) 
-p (Set Password) 
-r (Recurse) 
-sfx (create SFX) 
-si (use StdIn) 
-so (use StdOut) 
-ssw (Compress shared files) 
-t (Type of archive) 
-u (Update) 
-v (Volumes) 
-w (Working Dir) 
-x (Exclude) 
b: Benchmark 
d: Deletes files from archive. 從壓縮包中刪除文件 
d命令可用參數: 
-i (Include) 
-m (Method) 
-p (Set Password) 
-r (Recurse) 
-u (Update) 
-w (Working Dir) 
-x (Exclude) 
e: Extract解壓文件至當前目錄或指定目錄 
e命令可用參數: 
-ai (Include archives) 
-an (Disable parsing of archive_name) 
-ao (Overwrite mode) 
-ax (Exclude archives) 
-i (Include) 
-o (Set Output Directory) 
-p (Set Password) 
-r (Recurse) 
-so (use StdOut) 
-x (Exclude) 
-y (Assume Yes on all queries) 

l: Lists contents of archive. 
t: Test 
u: Update 

x: eXtract with full paths用文件的完整路徑解壓至當前目錄或指定目錄 
x命令可用參數: 
-ai (Include archives) 
-an (Disable parsing of archive_name) 
-ao (Overwrite mode) 
-ax (Exclude archives) 
-i (Include) 
-o (Set Output Directory) 
-p (Set Password) 
-r (Recurse) 
-so (use StdOut) 
-x (Exclude) 
-y (Assume Yes on all queries) 
-m (Set compression Method) switch 
Specifies the compression method.

1) 簡介
7z,全稱7-Zip, 是一款開源軟件。是目前公認的壓縮比例最大的壓縮解壓軟件。
主頁:http://www.7-zip.org/
中文主頁:http://7z.sparanoid.com/
命令行版本下載:http://7z.sparanoid.com/download.html
主要特徵:

全新的LZMA算法加大了7z格式的壓縮比

支持格式:

  • 壓縮 / 解壓縮:7z, XZ, BZIP2, GZIP, TAR, ZIP
  • 僅解壓縮:ARJ, CAB, CHM, CPIO, DEB, DMG, FAT, HFS, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, RAR, RPM, UDF, VHD, WIM, XAR, Z

2)退出代碼
0 : 正常,沒有錯誤;
1 : 警告,沒有致命的錯誤,例如某些文件正在被使用,沒有被壓縮;
2 : 致命錯誤;
7 : 命令行錯誤;
8 : 沒有足夠的內存;
255 : 用戶停止了操作;

3)使用語法
7z <命令行> [<選項>...] <基本檔案名稱> [<參數變量>...]

在方括號內的表達式(“[” 和 “]”之間的字符)是可選的。
在書名號內的表達式(“<” 和 “>”之間的字符)是必須替換的表達式(而且要去掉括號)。

7-Zip 支持和 Windows 相類似的通配符:
”可以使用星號代替零個或多個字符。 
“?”可以用問號代替名稱中的單個字符。
如果只用
,7-Zip 會將其視爲任何擴展名的全部文件。

4)命令及實例

a 添加文件到壓縮檔案。
7z a archive1.zip subdir\ :增加subdir文件夾下的所有的文件和子文件夾到archive1.zip中,archived1.zip中的文件名包含subdir\前綴。
7z a archive2.zip .\subdir* :增加subdir文件夾下的所有的文件和子文件夾到archive1.zip中,archived2.zip中的文件名不包含subdir\前綴。
cd /D c:\dir1\ 
7z a c:\archive3.zip dir2\dir3\ :archiive3.zip中的文件名將包含dir2\dir3\前綴,但是不包含c:\dir1前綴。
7z a Files.7z *.txt -r : 增加當前文件夾及其子文件夾下的所有的txt文件到Files.7z中。

b 測試 CPU 運行速度及檢查內存錯誤。

d 從壓縮檔案刪除文件。
7z d archive.zip *.bak -r :從archive.zip中刪除所有的bak文件。

e 從壓縮檔案中釋放文件到當前目錄中。或者到指定的輸出文件夾。輸出文件夾設置可以通過 -o (設置輸出文件夾) 選項來更改。此命令會將所有被釋放的文件放置到一個文件夾。如果您想使用完整路徑釋放文件,您必須使用 x (完整路徑釋放) 命令。 
7z e archive.zip :從壓縮檔案 archive.zip 中釋放所有文件到當前文件夾。
7z e archive.zip -oc:\soft .cpp :從壓縮檔案 archive.zip 中釋放 .cpp 文件到 c:\soft 文件夾。

l 列出壓縮檔案內容。
7z l archive.zip :列出壓縮檔案 archive.zip 的內容。

t 測試壓縮檔案文件的完整性。
7z t archive.zip .doc :在壓縮檔案 archive.zip 中測試 .doc 文件的完整性。

u 在壓縮檔案文件中使用較新的文件替換掉較舊的文件。
7z u archive.zip .doc :在壓縮檔案 archive.zip 中更新 .doc 文件。

x 在當前目錄中,使用完整路徑從壓縮檔案中釋放文件.或者到指定的輸出文件夾。
7z x archive.zip :從壓縮檔案 archive.zip 中釋放所有文件到當前文件夾。
7z x archive.zip -oc:\soft .cpp :從壓縮檔案 archive.zip 中釋放 .cpp 文件到 c:\soft 文件夾。

5)更多的選項

-- 在命令行中使“--”後的選項開關“-”都失效。這樣就允許在命令行中使用文件名以“-”開頭的文件。
7z t -- -ArchiveName.7z :測試 -ArchiveName.7z 壓縮檔案.

-i指定壓縮時附加文件或一類文件。此選項可附件添加多個類型。
i[<recurse_type>]<file_ref> 其中<recurse_type>爲可以爲r[- | 0](具體的-r選項見後面-r),<file_ref>可以爲@{listfile} | !{wildcard}。
7z a -tzip src.zip .txt -ir!DIR1*.cpp :從當前目錄中添加 .txt 文件,和 DIR1 目錄及其子目錄中的 *.cpp 文件到 src.zip 壓縮檔案。

-x 指定某一文件或某一類文件從操作中排除。此選項可同時排除多個類型。
x[<recurse_type>]<file_ref> 其中<recurse_type>爲可以爲r[- | 0](具體的-r選項見後面-r),<file_ref>可以爲@{listfile} | !{wildcard}。
7z a -tzip archive.zip .txt -x!temp. :添加除 temp. 文件之外的所有 .txt 文件到壓縮檔案 archive.zip。

-o 指定釋放文件的輸出文件夾。此選項只能和釋放命令配合使用。
7z x archive.zip -oc:\Doc :從 archive.zip 壓縮檔案釋放所有文件到 c:\Doc 文件夾。

-r 遞歸子目錄選項。
-r 開啓遞歸子目錄。對於 e (釋放)、l (列表)、t (測試)、x (完整路徑釋放) 這些在壓縮檔案中操作的命令, 會默認使用此選項。 
-r- 關閉遞歸子目錄。對於 a (添加)、d (刪除)、u (更新) 等所有需掃描磁盤文件的命令,會默認使用此選項。 
-r0 開啓遞歸子目錄。但只應用於通配符。 
7z l archive.zip -r- .doc :列出在 archive.zip 壓縮檔案中根目錄下的 .doc 文件。 
7z a -tzip archive.zip -r src*.cpp src*.h :將 src 目錄及其子目錄中的 .cpp 及 .h 文件添加到 archive.zip 壓縮檔案。

-t 指定壓縮檔案格式。指定壓縮檔案格式。它們可以是:zip、7z、rar、cab、gzip、bzip2、tar 或其它格式。而 默認值是 7z 格式。 
7z a -tzip archive.zip .txt :使用 zip 格式從當前目錄中添加所有 .txt 文件到壓縮檔案 archive.zip。

-y 使 7-Zip 執行命令時的大多數提示失效。您可以使用此選項來阻止在 e (釋放) 和 x (完整路徑釋放) 命令中文件覆蓋時的提示。
7z x src.zip -y :從 src.zip 釋放所有文件。所有的覆蓋提示將被阻止且所有相同文件名的文件將被覆蓋。

-v指定分卷大小。
{Size}[b | k | m | g] 
指定分卷大小,可以使用字節、KB(1 KB=1024 字節),MB(1 MB = 1024 KB)或 GB(1 GB = 1024 MB)。如果您只指定了 {Size},7-zip 將把它視爲字。 
7z a a.7z *.txt -v10k -v15k -v2m : 創建 a.7z 分卷壓縮檔案。第一個分卷爲 10 KB,第二個爲 15 KB,剩下全部爲 2 MB。

-p 指定密碼。
7z x archive.zip -psecret :將設有密碼“secret”的壓縮檔案 archive.zip 中所有文件釋放。

-ao 指定在釋放期間如何覆蓋硬盤上現有的同名文件。
語法:-ao[a | s | u ]
-aoa 直接覆蓋現有文件,而沒有任何提示。 
-aos 跳過現有文件,其不會被覆蓋。 
-aou 如果相同文件名的文件以存在,將自動重命名被釋放的文件。舉個例子,文件 file.txt 將被自動重命名爲 file_1.txt。 
-aot 如果相同文件名的文件以存在,將自動重命名現有的文件。舉個例子,文件 file.txt 將被自動重命名爲 file_1.txt。 
7z x test.zip -aoa :從壓縮檔案 test.zip 中釋放所有文件並卻不做提示直接覆蓋現有文件。

-an 不解析命令行中的 archive_name 區域。此選項必須和 -i (附加文件) 開關一起使用。比如您爲壓縮檔案使用列表文件,您就需要指定 -ai 選項,所以您需要禁止解析命令行中的 archive_name 區域。
實例見後面的-ai和-ax中。

-ai 指定附加文件,包括壓縮檔案文件名及通配符。此選項可同時附加多個類型。
ai[<recurse_type>]<file_ref> 其中<recurse_type>爲可以爲r[- | 0](具體的-r選項見後面-r),<file_ref>可以爲@{listfile} | !{wildcard}。
7z t -an -air!.7z : 在當前目錄及子目錄下測試 .7z 壓縮檔案。

-ax 指定必須從操作中排除的壓縮檔案。此選項可同時排除多個類型。
ax[<recurse_type>]<file_ref> 其中<recurse_type>爲可以爲r[- | 0](具體的-r選項見後面-r),<file_ref>可以爲@{listfile} | !{wildcard}。
7z t -an -ai!.7z -ax!a.7z :測試除 a.7z 之外的 .7z 壓縮檔案。

更多的不常用的選項,可以查看幫助。例如:-m設置壓縮算法;-scs 設置要壓縮的文件的列表文件的字符集;-seml通過電子郵件發送壓縮檔;-sfx創建自釋放檔;-si從標準輸入讀入數據,-so從輸出到標準輸 出;-slp設置大內存模式;-slt顯示技術信息;-ssc設置區分大小寫;-ssw壓縮正在寫入的文件;-u更新選項。

轉自:http://www.cnblogs.com/qanholas/archive/2011/10/03/2198487.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章