zip 命令能夠用來壓縮、打包文件。linux
#Debian/Ubuntu安裝 apt-get install zip #CentOS安裝 [root@centos7 testdir]# zip -bash: zip: command not found [root@centos7 testdir]# yum install zip -y
zip 命令也能夠用來解壓縮文件,zip也是一個經常使用的壓縮、解壓應用程序,文件經它壓縮後會產生一個新以.zip爲擴展名的壓縮包文件。centos
zip [ OPTIONS ] [ NAME ..]
-A #調整可執行的自動解壓縮文件 -b<工做目錄> #指定壓縮文件的存放目錄 -c #給每一個被壓縮的文件加上註釋信息 -d #從壓縮文件內刪除指定的文件,也能夠使用--delete參數 -D #壓縮文件內不創建目錄名稱 -f #更新既有文件,將其它文件一併加入到壓縮文件中 -F #修復已損壞的壓縮文件 -g #將指定文件壓縮至已存在的壓縮文件中,不創建新文件 -h #打印幫助信息 -i<範本樣式> #只壓縮匹配指定條件的文件 -m #將指定文件壓縮打包後直接刪除原始文件 -o #將壓縮文件的屬性信息更改爲與壓縮文件中的最新文件的屬性一致 -q #安靜模式 -r #遞歸處理 -t<日期時間> #把壓縮文件的日期設成指定的日期 -T #檢查備份文件內的每一個文件是否正確無誤 -u #更新較新的文件到壓縮文件內 -v #打印命令執行過程信息或版本信息 -x<範本樣式> #壓縮時排除符合條件的文件 -z #給壓縮文件加上註釋信息 -<壓縮效率> #指定壓縮效率(1~9數字)
在當前目錄下建立壓縮文件(自動建立以.zip的文件)bash
[root@centos7 testdir]# zip mingongge * adding: cest.txt.gz (stored 0%) adding: cuttest.txt.gz (stored 0%) adding: dir/ (stored 0%) adding: file (stored 0%) adding: mingongge1.txt.gz (stored 0%) adding: mingongge2.txt.gz (stored 0%) adding: mingongge.txt.md5.gz (stored 0%) adding: sort.cut.txt.gz (stored 0%)
分割一個大文件centos7
[root@centos7 ~]# ls -lh total 22M -rw-------. 1 root root 1.3K Aug 20 10:39 anaconda-ks.cfg -rw-r--r-- 1 root root 140 Jan 16 11:36 dos_test.txt drwxr-xr-x 3 root root 39 Aug 30 03:48 goinception -rw-r--r-- 1 root root 13M Aug 30 03:42 goInception-linux-amd64-v1.2.3.tar.gz drwxr-sr-x 11 root 40 4.0K Dec 24 22:35 httpd-2.4.46 -rw-r--r-- 1 root root 9.0M Aug 5 07:32 httpd-2.4.46.tar.gz -rw-r--r-- 1 root root 0 Jan 16 11:32 mingongge.file drwxr-xr-x 3 root root 192 Jan 16 16:19 testdir -rw-r--r-- 1 root root 140 Jan 16 11:32 test.txt [root@centos7 ~]# zip -s 4M -r mingongge.zip httpd-2.4.46.tar.gz adding: httpd-2.4.46.tar.gz (deflated 0%) [root@centos7 ~]# ls -lh total 31M -rw-------. 1 root root 1.3K Aug 20 10:39 anaconda-ks.cfg -rw-r--r-- 1 root root 140 Jan 16 11:36 dos_test.txt drwxr-xr-x 3 root root 39 Aug 30 03:48 goinception -rw-r--r-- 1 root root 13M Aug 30 03:42 goInception-linux-amd64-v1.2.3.tar.gz drwxr-sr-x 11 root 40 4.0K Dec 24 22:35 httpd-2.4.46 -rw-r--r-- 1 root root 9.0M Aug 5 07:32 httpd-2.4.46.tar.gz -rw-r--r-- 1 root root 0 Jan 16 11:32 mingongge.file -rw-r--r-- 1 root root 4.0M Jan 16 16:24 mingongge.z01 -rw-r--r-- 1 root root 4.0M Jan 16 16:24 mingongge.z02 -rw-r--r-- 1 root root 943K Jan 16 16:24 mingongge.zip drwxr-xr-x 3 root root 192 Jan 16 16:19 testdir #從結果能夠看出會拆分紅三個文件即:4M大小的mingongge.z0一、4M大小的mingongge.z02和一個943k的mingongge.zip文件。