zip 功能说明:zip压缩格式是Windows与Linux等多个平台通用的压缩格式。 和gzip命令相比,zip命令压缩文件不仅不会删除源文件,而且还可以压缩目录。 参数选项: -r 将指定目录下的所有文件和子目录一并压缩。 -x 压缩文件时排除某个文件。 -q 不显示压缩信息。 压缩文件: [root@testdb ~]# touch a.log [root@testdb ~]# zip a.log.zip a.log adding: a.log (stored 0%) [root@testdb ~]# ll a.log* -rw-r--r-- 1 root root 0 Dec 17 19:46 a.log -rw-r--r-- 1 root root 160 Dec 17 19:46 a.log.zip 压缩目录 这样只是压缩目录这一个文件,目录下的文件没有压缩 [root@testdb ~]# cd / [root@testdb /]# zip tmp.zip ./tmp adding: tmp/ (stored 0%) [root@testdb /]# ls -l tmp.zip -rw-r--r-- 1 root root 158 Dec 17 19:50 tmp.zip [root@testdb /]# sz tmp.zip 递归压缩目录 [root@testdb ~]# cd / [root@testdb /]# zip -r tmp2.zip ./tmp/ adding: tmp/ (stored 0%) adding: tmp/.ICE-unix/ (stored 0%) adding: tmp/my_local.tar.gz (stored 0%) adding: tmp/.XIM-unix/ (stored 0%) adding: tmp/.Test-unix/ (stored 0%) adding: tmp/.X11-unix/ (stored 0%) adding: tmp/systemd-private-f27c798346264f1c9a989f1fc639f777-ntpd.service-tenujt/ (stored 0%) adding: tmp/systemd-private-f27c798346264f1c9a989f1fc639f777-ntpd.service-tenujt/tmp/ (stored 0%) adding: tmp/logs/ (stored 0%) adding: tmp/logs/2.log (stored 0%) adding: tmp/logs/10.log (stored 0%) adding: tmp/logs/1.log (stored 0%) adding: tmp/logs/3.log (stored 0%) adding: tmp/logs/7.log (stored 0%) adding: tmp/logs/6.log (stored 0%) adding: tmp/logs/5.log (stored 0%) adding: tmp/logs/4.log (stored 0%) adding: tmp/logs/8.log (stored 0%) adding: tmp/logs/9.log (stored 0%) adding: tmp/stargate.lock (stored 0%) adding: tmp/.font-unix/ (stored 0%) [root@testdb /]# ls -l tmp2.zip -rw-r--r-- 1 root root 4063 Dec 17 19:54 tmp2.zip 排除压缩 [root@testdb ~]# cd / [root@testdb /]# [root@testdb /]# zip -r tmp3.zip ./tmp/ -x tmp/dir1/1.log adding: tmp/ (stored 0%) adding: tmp/a.log (stored 0%) adding: tmp/b.log (stored 0%) adding: tmp/dir1/ (stored 0%) adding: tmp/dir1/2.log (stored 0%) adding: tmp/stargate.lock (stored 0%) adding: tmp/dir2/ (stored 0%) adding: tmp/dir2/2.log (stored 0%) adding: tmp/dir2/21.log (stored 0%) [root@testdb /]# zip -r tmp4.zip ./tmp/ -x tmp/dir1/* adding: tmp/ (stored 0%) adding: tmp/a.log (stored 0%) adding: tmp/b.log (stored 0%) adding: tmp/dir1/ (stored 0%) adding: tmp/stargate.lock (stored 0%) adding: tmp/dir2/ (stored 0%) adding: tmp/dir2/2.log (stored 0%) adding: tmp/dir2/21.log (stored 0%) [root@testdb /]# zip -r tmp5.zip ./tmp/ -x tmp/dir1/1.log -x tmp/dir2/2.log adding: tmp/ (stored 0%) adding: tmp/a.log (stored 0%) adding: tmp/b.log (stored 0%) adding: tmp/dir1/ (stored 0%) adding: tmp/dir1/2.log (stored 0%) adding: tmp/stargate.lock (stored 0%) adding: tmp/dir2/ (stored 0%) adding: tmp/dir2/21.log (stored 0%)