zip命令
zip 壓縮包在 Windows 和 Linux 都比較常見的,zip命令本身即能歸檔又能壓縮,
-
功能說明:對一個檔案或多個檔案進行壓縮
-
用法:zip [選項] 壓縮檔案名.zip FILE…
選項 作用 -r 對目錄下的檔案及子目錄進行遞回壓縮 -d 從壓縮檔案內洗掉指定檔案 -q 壓縮時不顯示命令執行程序 -x 壓縮時排除某些檔案不壓縮
示例:復制/var/log/messages到/tmp/compress目錄并對messages檔案進行壓縮,
[root@node1 ~]# cd /tmp/ && mkdir compress
[root@node1 tmp]# cd compress
[root@node1 compress]# cp /var/log/messages ./
[root@node1 compress]# ll -h
total 44K
-rw------- 1 root root 42K Feb 25 14:38 messages
[root@node1 compress]# zip messages.zip messages
adding: messages (deflated 94%)
[root@node1 compress]# ll -h
total 48K
-rw------- 1 root root 42K Feb 25 14:38 messages
-rw-r--r-- 1 root root 2.9K Feb 25 14:39 messages.zip
說明: zip 后面先跟目標檔案名,也就是壓縮后的自定義壓縮包名,然后是要壓縮的檔案或者目錄,
示例:將/var/log下的所有目錄及檔案復制到/tmp目錄,并使用zip進行歸檔,
[root@node1 compress]# cp -r /var/log/ /tmp/
[root@node1 compress]# du -sh /tmp/log/
3.9M /tmp/log/
[root@node1 compress]# cd ..
[root@node1 tmp]# zip -r -q log.zip log/
[root@node1 tmp]# ll -h
total 416K
drwxr-xr-x 2 root root 42 Feb 25 14:39 compress
drwxr-xr-x 8 root root 4.0K Feb 25 14:40 log
-rw-r--r-- 1 root root 411K Feb 25 14:42 log.zip
示例:生成1..10.txt的檔案,壓縮時不對10.txt進行壓縮,
[root@node1 tmp]# mkdir test
[root@node1 tmp]# cd test/
[root@node1 test]# for i in {1..10}.txt;do touch $i;done
[root@node1 test]# ls
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
[root@node1 test]# zip text.zip *.txt -x 10.txt
adding: 1.txt (stored 0%)
adding: 2.txt (stored 0%)
adding: 3.txt (stored 0%)
adding: 4.txt (stored 0%)
adding: 5.txt (stored 0%)
adding: 6.txt (stored 0%)
adding: 7.txt (stored 0%)
adding: 8.txt (stored 0%)
adding: 9.txt (stored 0%)
unzip命令
-
功能說明:對zip壓縮檔案進行解壓縮
-
用法:unzip [選項] 壓縮檔案名.zip
選項 作用 -l 列出壓縮檔案內的檔案 -d 指定檔案解壓后的目錄,默認為當前目錄 -q 解壓時不顯示命令執行程序 -t 測驗壓縮檔案是否損壞
示例:解壓text.zip壓縮檔案到當前目錄,
[root@node1 test]# ls
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt text.zip
[root@node1 test]# rm -f *.txt
[root@node1 test]# unzip text.zip
Archive: text.zip
extracting: 1.txt
extracting: 2.txt
extracting: 3.txt
extracting: 4.txt
extracting: 5.txt
extracting: 6.txt
extracting: 7.txt
extracting: 8.txt
extracting: 9.txt
示例:查看text.zip壓縮檔案中的資訊,
[root@node1 test]# unzip -l text.zip
Archive: text.zip
Length Date Time Name
--------- ---------- ----- ----
0 02-25-2018 14:44 1.txt
0 02-25-2018 14:44 2.txt
0 02-25-2018 14:44 3.txt
0 02-25-2018 14:44 4.txt
0 02-25-2018 14:44 5.txt
0 02-25-2018 14:44 6.txt
0 02-25-2018 14:44 7.txt
0 02-25-2018 14:44 8.txt
0 02-25-2018 14:44 9.txt
--------- -------
0 9 files
示例:解壓log.zip檔案到/tmp/new目錄
[root@node1 test]# cd ..
[root@node1 tmp]# ls
compress log log.zip test
[root@node1 tmp]# unzip -q log.zip -d new/
[root@node1 tmp]# ll new/
total 4
drwxr-xr-x 8 root root 4096 Feb 25 14:40 log
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/79178.html
標籤:Linux
上一篇:Linux命令(5)tar命令
