[備份] [Tools] 7-Zip的命令列指令
當我們需要整批壓縮檔案或要透過排程來備份資料時,最方便的還是使用命令列指令。由於從DOS時就慣用PKZIP,因此到現在仍繼續使用它的PkzipC.exe,但最近因為硬碟空間不足且因為Pkzipc是需要付費的,因此順便將之整個更換成7-Zip 的命令列指令:7z.exe,同時將壓縮格式換成7z,使空間能更節省。
7z.exe的命令語法如下:
7z 命令 [選項] 壓縮檔名 要處理的檔名列
命令:有a,d,e,l,t,u, x等幾個命令。
a | Add | 將檔名列中的檔案加入壓縮檔 | -i (Include)? |
-m (Method)? | |||
-p (Set Password)? | |||
-r (Recurse)? | |||
-sfx (create SFX)? | |||
-si (use StdIn)? | |||
-so (use StdOut)? | |||
-t (Type of archive)? | |||
-u (Update)? | |||
-v (Volumes)? | |||
-w (Working Dir)? | |||
-x (Exclude) | |||
d | Delete | 將指定檔名由壓縮檔內移除 | -i (Include) |
-m (Method) | |||
-p (Set Password) | |||
-r (Recurse) | |||
-u (Update) | |||
-w (Working Dir) | |||
-x (Exclude) | |||
e | Extract | 將指定檔名由壓縮檔中擷取出來 | -ai (Include archives) |
-an (Disable parsing of archive_name) | |||
-ao (Overwrite mode) | |||
-ai (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 | List | 顯示壓縮檔案內的檔案資訊 | -ai (Include archives) |
-an (Disable parsing of archive_name) | |||
-ai (Exclude archives) | |||
-i (Include) | |||
-p (Set Password) | |||
-r (Recurse) | |||
-x (Exclude) | |||
t | Test | 測試壓縮檔的完整性 | -ai (Include archives) |
-an (Disable parsing of archive_name) | |||
-ai (Exclude archives) | |||
-i (Include) | |||
-p (Set Password) | |||
-r (Recurse) | |||
-x (Exclude) | |||
u | Update | 用較新的同名檔案更新壓縮檔內較舊的檔案 | -i (Include) |
-m (Method) | |||
-p (Set Password) | |||
-r (Recurse) | |||
-sfx (create SFX) | |||
-si (use StdIn) | |||
-so (use StdOut) | |||
-t (Type of archive) | |||
-u (Update) | |||
-w (Working Dir) | |||
-x (Exclude) | |||
x | eXtract with full paths | 以完整路徑的格式解出檔案 | -ai (Include archives) |
-an (Disable parsing of archive_name) | |||
-ao (Overwrite mode) | |||
-ai (Exclude archives) | |||
-i (Include) | |||
-o (Set Output Directory) | |||
-p (Set Password) | |||
-r (Recurse) | |||
-so (use StdOut) | |||
-x (Exclude) | |||
-y (Assume Yes on all queries) |
範例:
- 壓縮檔案:7z a -tzip archive.zip test1.txt test2.txt test3.txt
- 刪除檔案:7z d archive.zip *.bak
- 解壓縮到目前資料夾:7z e archive.zip
- 解壓縮所有的.cpp檔案案件到指定資料夾:7z e archive.zip -oc:\soft *.cpp
- 顯示壓縮檔內的資訊:7z l archive.zip
- 依壓縮檔內的檔案路徑解壓縮到指定資料夾:7z x archive.zip -oc:\soft *.cpp
更詳細的內容直接看到7-zip.chm即可。
做了一點小測試:將資料夾內30個檔案大小共260,823,040 Bytes的檔案(SQL Server資料庫備份出的資料檔案),分別使用7-Zip、PkzipC、WinRAR 3.0
壓縮,大小分別同下:
- 7-Zip: 43,791,855 Bytes
- WinRAR: 50,415,283 Bytes
- PKZipC: 63,701,625 Bytes
獲勝的是7-Zip。
沒有留言:
張貼留言