天天看點

mac 指令行 解壓7z檔案_7z指令行

7z --help

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21

p7zip Version 16.02 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64)

Usage: 7z [...] [...]

[]

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

-- : 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

必選參數:最常用的指令有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

解壓指令(1):7z e filename.7z

解壓指令(2):7z x -tzip -y xx-13.zip (解壓到目前目錄,如需改變輸出目錄,需要附加使用-o)

壓縮指令:7z a -tzip -r xx.zip a* b*

将目錄a、目錄b,壓縮成一個xx.zip

主要特征:

全新的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[] 其中為可以為r[- | 0](具體的-r選項見後面-r),可以為@{listfile} | !{wildcard}。

7z a -tzip src.zip *.txt -ir!DIR1*.cpp :從目前目錄中添加 *.txt 檔案,和 DIR1 目錄及其子目錄中的 *.cpp 檔案到 src.zip 壓縮檔案。

-x 指定某一檔案或某一類檔案從操作中排除。此選項可同時排除多個類型。

x[] 其中為可以為r[- | 0](具體的-r選項見後面-r),可以為@{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[] 其中為可以為r[- | 0](具體的-r選項見後面-r),可以為@{listfile} | !{wildcard}。

7z t -an -air!*.7z : 在目前目錄及子目錄下測試 *.7z 壓縮檔案。

-ax 指定必須從操作中排除的壓縮檔案。此選項可同時排除多個類型。

ax[] 其中為可以為r[- | 0](具體的-r選項見後面-r),可以為@{listfile} | !{wildcard}。

7z t -an -ai!.7z -ax!a.7z :測試除 a*.7z 之外的 *.7z 壓縮檔案。

更多的不常用的選項,可以檢視幫助。例如:-m設定壓縮算法;-scs 設定要壓縮的檔案的清單檔案的字元集;-seml通過電子郵件發送壓縮檔;-sfx建立自釋放檔;-si從标準輸入讀入資料,-so從輸出到标準輸 出;-slp設定大記憶體模式;-slt顯示技術資訊;-ssc設定區分大小寫;-ssw壓縮正在寫入的檔案;-u更新選項。

Mac安裝7z解壓指令

brew直接安裝解壓工具

$ brew search 7z

p7zip

$ brew install p7zip

######################################################################## 100.0%

==> make all3 CC=clang $(ALLFLAGS) CXX=clang++ $(ALLFLAGS)

==> make DEST_HOME=/usr/local/Cellar/p7zip/9.20.1 DEST_MAN=/usr/local/Cellar/p7zip/9.20.1/share/man install

==> chmod -R +w /usr/local/Cellar/p7zip/9.20.1/share/doc/p7zip