7zip 命令行模式命令行簡介


 

 

命令格式

7z <command> [<switch>...] <base_archive_name> [<arguments>...]

 

7z +操作的名稱+  +操作的參數+  +打包文件名+  +要打包的文件+  +其他參數+

 

壓縮

a (Add) command

添加文件到壓縮包中

 

7z a out1.zip in_dir\ //指定的是目錄名

 

in_dir \之下的所有的文件和子目錄都添加到archive1.zip中。壓縮包中的所有文件名都會包含in_dir \前綴。解壓時得到的是in_dir目錄。壓縮的是目錄,解壓得到的也是目錄。

 

7z a out1.zip in_dir \* 7z a out1.zip in_dir \ 是一樣的。

 

7z a out3.zip .\ in_dir \* //指定的是文件名

 

in_dir \之下的所有的文件和子目錄都添加到out3.zip中。壓縮包中的所有文件名都不包含in_dir \前綴。X命令解壓時直接得到各個文件和子目錄。

 

7z a out.zip  -r

 

當前目錄下的所有文件和子目錄打包到out.zip

 

壓縮后刪除原文件

-sdel (Delete files after compression) switch

 

使用這個選項的作用就像是剪切。

 

7z a a.7z *.txt -sdel

 

moves txt files from disk's directory to a.7z archive.

 

使用一個文件列表指定文件名

 

 

List file

You can supply one or more filenames or wildcards for special list files (files containing lists of files). The filenames in such list file must be separated by new line symbol(s).

For list files, 7-Zip uses UTF-8 encoding by default. You can change encoding using -scs switch. Multiple list files are supported.

For example, if the file "listfile.txt" contains the following:

 

    My programs\*.cpp

    Src\*.cpp

 

then the command

 

    7z a -tzip archive.zip @listfile.txt

 

adds to the archive "archive.zip" all "*.cpp" files from directories "My programs" and "Src".

 

指定打包文件格式

7z a -tzip archive.zip *.txt

 

adds all *.txt files from current directory to zip archive archive.zip.

 

7z t -t7z.split archive.7z.001

 

tests all files in archive.7z.001. It also checks that archive is multivolume .7z archive.

 

7z x -t# sfxarchive.exe

 

extracts sfxarchive.exe in parser mode.

 

7z x -tiso archive.iso

 

extracts files from archive.iso open as ISO archive.

 

7z x -tudf archive.iso

 

extracts files from archive.iso open as UDF archive.

 

如果沒有使用-t{archive_type}指定類型,那么7zip會使用擴展名來決定打包類型。創建新的壓縮包,如果沒有指定類型,也沒有擴展名,會默認創建.7z類型壓縮包

 

 

輸出壓縮包中所有的文件

l (List contents of archive) command

Lists contents of archive,包括文件名,以及文件大小、類型等信息。

 

命令:7za.exe l out3.zip

 

輸出

 

 

 

out3.zip里包含的是5文件,而不是兩個文件和1一個子目錄一個文件中不會包含目錄。只不過使用x命令解壓的時候可以創建dir1子目錄。

所以 dir1\11.txt 中的dir1 “文件名前綴”,而不是目錄名。

 

從壓縮包中刪除文件

d (Delete) command

Deletes files from archive.

 

Example

7z d archive.zip *.bak -r

 

deletes *.bak files from archive archive.zip.

 

解壓

解壓有兩個命令,e xe命令解壓的時候不會保持目錄結構,會把所有的文件都解壓到目的目錄下,不管這些文件是不是位於子文件夾。

x命令則會保存目錄結構。以上面out3.zip為例,

命令:7za.exe x –oout_dir out3.zip

out_dir的文件結構:

 

 

 

命令:7za.exe e –oout_dir out3.zip

out_dir的文件結構:

 

 

子目錄dir是空目錄。

 

設置密碼

-p{password} 指定壓縮或者解壓時的密碼。

 

7z a archive.7z -psecret -mhe *.txt

 

compresses *.txt files to archive.7z using password "secret". Also it encrypts archive headers (-mhe switch), so filenames will be encrypted.

注意有的參數是和格式關聯的,例如zip格式無法設置隱藏文件名對zip格式使用 –mhe 參數就無法成功執行。不同格式適用的不同命令參數見文檔。

 

7z x archive.zip -psecret

 

extracts all files from archive.zip using password "secret".

 

計算哈希

7zip另一項非常有用的功能是計算文件的哈希。使用h (Hash) 命令計算文件的哈希。

 

語法格式:h [-scrc{Method}] [files]

 

-scrc參數指定計算的方法,支持的方法有 CRC32, CRC64, SHA1, SHA256. 默認是 CRC32.

 

Examples

7z h a.txt

calculates CRC32 for a.txt.

 

7z h -scrcsha256 a.iso

calculates SHA256 for a.iso.

 

7z h *

calculates CRC32 for all files in current folder and all subfolders.

 

Notes

7-Zip shows hash values for each file, the sum of hash values and the sum that includes all hash values of data and all hash values for filenames.

7-Zip represents hash values for CRC32 and CRC64 as integer numbers in hex.

7-Zip represents hash values For SHA1 and SHA256 as sequence of bytes in hex.

 


免責聲明!

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



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