【Linux】一步一步学Linux——zip命令(67)
00. 目錄
文章目錄
- 00. 目錄
- 01. 命令概述
- 02. 命令格式
- 03. 常用選項(xiàng)
- 04. 參考示例
- 05. 附錄
01. 命令概述
zip 命令是一個(gè)應(yīng)用廣泛的跨平臺(tái)的壓縮工具,壓縮文件的后綴為 .zip文件
zip程序?qū)⒁粋€(gè)或多個(gè)壓縮文件與有關(guān)文件的信息(名稱(chēng)、路徑、日期、上次修改的時(shí)間、保護(hù)和檢查信息以驗(yàn)證文件完整性)一起放入一個(gè)壓縮存檔中。可以使用一個(gè)命令將整個(gè)目錄結(jié)構(gòu)打包到zip存檔中。
對(duì)于文本文件來(lái)說(shuō),壓縮比為2:1和3:1是常見(jiàn)的。zip只有一種壓縮方法(通縮),并且可以在不壓縮的情況下存儲(chǔ)文件。(如果添加了bzip 2支持,zip也可以使用bzip 2壓縮,但這些條目需要一個(gè)合理的現(xiàn)代解壓縮來(lái)解壓縮。當(dāng)選擇bzip 2壓縮時(shí),它將通貨緊縮替換為默認(rèn)方法。)zip會(huì)自動(dòng)為每個(gè)要壓縮的文件選擇更好的兩個(gè)文件(通縮或存儲(chǔ),如果選擇bzip2,則選擇bzip2或Store)。
02. 命令格式
zip [參數(shù)] [文件]03. 常用選項(xiàng)
-A:調(diào)整可執(zhí)行的自動(dòng)解壓縮文件; -b<工作目錄>:指定暫時(shí)存放文件的目錄; -c:替每個(gè)被壓縮的文件加上注釋; -d:從壓縮文件內(nèi)刪除指定的文件; -D:壓縮文件內(nèi)不建立目錄名稱(chēng); -f:此參數(shù)的效果和指定“-u”參數(shù)類(lèi)似,但不僅更新既有文件,如果某些文件原本不存在于壓縮文件內(nèi),使用本參數(shù)會(huì)一并將其加入壓縮文件中; -F:嘗試修復(fù)已損壞的壓縮文件; -g:將文件壓縮后附加在已有的壓縮文件之后,而非另行建立新的壓縮文件; -h:在線幫助; -i<范本樣式>:只壓縮符合條件的文件; -j:只保存文件名稱(chēng)及其內(nèi)容,而不存放任何目錄名稱(chēng); -J:刪除壓縮文件前面不必要的數(shù)據(jù); -k:使用MS-DOS兼容格式的文件名稱(chēng); -l:壓縮文件時(shí),把LF字符置換成LF+CR字符; -ll:壓縮文件時(shí),把LF+cp字符置換成LF字符; -L:顯示版權(quán)信息; -m:將文件壓縮并加入壓縮文件后,刪除原始文件,即把文件移到壓縮文件中; -n<字尾字符串>:不壓縮具有特定字尾字符串的文件; -o:以壓縮文件內(nèi)擁有最新更改時(shí)間的文件為準(zhǔn),將壓縮文件的更改時(shí)間設(shè)成和該文件相同; -q:不顯示指令執(zhí)行過(guò)程; -r:遞歸處理,將指定目錄下的所有文件和子目錄一并處理; -S:包含系統(tǒng)和隱藏文件; -t<日期時(shí)間>:把壓縮文件的日期設(shè)成指定的日期; -T:檢查備份文件內(nèi)的每個(gè)文件是否正確無(wú)誤; -u:更換較新的文件到壓縮文件內(nèi); -v:顯示指令執(zhí)行過(guò)程或顯示版本信息; -V:保存VMS操作系統(tǒng)的文件屬性; -w:在文件名稱(chēng)里假如版本編號(hào),本參數(shù)僅在VMS操作系統(tǒng)下有效; -x<范本樣式>:壓縮時(shí)排除符合條件的文件; -X:不保存額外的文件屬性; -y:直接保存符號(hào)連接,而非該鏈接所指向的文件,本參數(shù)僅在UNIX之類(lèi)的系統(tǒng)下有效; -z:替壓縮文件加上注釋; -$:保存第一個(gè)被壓縮文件所在磁盤(pán)的卷冊(cè)名稱(chēng); -<壓縮效率>:壓縮效率是一個(gè)介于1~9的數(shù)值。04. 參考示例
4.1 壓縮文件
[deng@localhost test]$ zip passwd.zip passwd adding: passwd (deflated 61%) [deng@localhost test]$ ls etc passwd passwd.zip test [deng@localhost test]$4.2 指定壓縮率為8
[deng@localhost test]$ zip passwd1.zip -8 passwdadding: passwd (deflated 61%) [deng@localhost test]$4.3 壓縮目錄
選項(xiàng) -r 表示遞歸壓縮子目錄下所有文件,將目錄 test壓縮為 test.zip
[deng@localhost test]$ zip -r test.zip testadding: test/ (stored 0%)adding: test/a (stored 0%)adding: test/b (stored 0%)adding: test/c (stored 0%)adding: test/d (stored 0%)adding: test/e (stored 0%) [deng@localhost test]$ ls etc passwd passwd1.zip passwd.zip test test.zip [deng@localhost test]$4.4 壓縮目錄和文件
將目錄test和文件paswd 壓縮成為 test1.zip
[deng@localhost test]$ zip -r test1.zip test passwdadding: test/ (stored 0%)adding: test/a (stored 0%)adding: test/b (stored 0%)adding: test/c (stored 0%)adding: test/d (stored 0%)adding: test/e (stored 0%)adding: passwd (deflated 61%) [deng@localhost test]$4.5 從壓縮文件內(nèi)刪除指定文件
[deng@localhost test]$ zip -d test1.zip passwd deleting: passwd [deng@localhost test]$4.6 向壓縮文件中添加指定文件
[deng@localhost test]$ zip -m test1.zip passwdadding: passwd (deflated 61%) [deng@localhost test]$4.7 壓縮文件時(shí)排除某個(gè)文件
[deng@localhost test]$ zip -r test2.zip test -x test/aadding: test/ (stored 0%)adding: test/b (stored 0%)adding: test/c (stored 0%)adding: test/d (stored 0%)adding: test/e (stored 0%) [deng@localhost test]$4.8 壓縮多個(gè)文件
[deng@localhost test]$ zip -v t.zip a b c d eadding: a (in=0) (out=0) (stored 0%)adding: b (in=0) (out=0) (stored 0%)adding: c (in=0) (out=0) (stored 0%)adding: d (in=0) (out=0) (stored 0%)adding: e (in=0) (out=0) (stored 0%) total bytes=0, compressed=0 -> 0% savings [deng@localhost test]$ ls a b c d e t.zip [deng@localhost test]$4.9 不顯示指令執(zhí)行過(guò)程
[deng@localhost test]$ zip -q a.zip a [deng@localhost test]$ zip b.zip aadding: a (stored 0%) [deng@localhost test]$05. 附錄
參考:【Linux】一步一步學(xué)Linux系列教程匯總
總結(jié)
以上是生活随笔為你收集整理的【Linux】一步一步学Linux——zip命令(67)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【Linux】一步一步学Linux——b
- 下一篇: 【Linux】一步一步学Linux——u