说明
zip压缩格式是很多计算机平台通用的压缩格式。和gzip命令相比,zip命令压缩不仅不会删除源文件,而且还可以压缩目录
格式
zip [option] [file]
常用参数
- -r:将指定目录下的所有文件和子目录一并压缩
- -x:压缩文件时排除某个文件
- -q:不显示压缩信息
示例
1、压缩文件
[root@localhost test]# cp /etc/services .
[root@localhost test]# ll -h services
-rw-r--r--. 1 root root 655K May 14 15:33 services
[root@localhost test]# zip services.zip ./services
adding: services (deflated 80%)
[root@localhost test]# ll -h services*
-rw-r--r--. 1 root root 655K May 14 15:33 services
-rw-r--r--. 1 root root 134K May 14 15:34 services.zip
2、压缩目录
[root@localhost ~]# zip test.zip ./test #不加-r参数将只会压缩目录这个额一个文件,所以这样使用不对
updating: test/ (stored 0%)
[root@localhost ~]# zip -r test.zip ./test #-r参数
adding: test/ (stored 0%)
adding: test/test_01.txt (stored 0%)
adding: test/test_02.txt (stored 0%)
adding: test/test_03.txt (stored 0%)
adding: test/test_04.txt (stored 0%)
adding: test/test_05.txt (stored 0%)
adding: test/test_06.txt (stored 0%)
adding: test/test_07.txt (stored 0%)
adding: test/test_08.txt (stored 0%)
adding: test/test_09.txt (stored 0%)
adding: test/test_10.txt (stored 0%)
adding: test/test_11.txt (stored 0%)
adding: test/test_12.txt (stored 0%)
adding: test/test.txt (stored 0%)
adding: test/services (deflated 80%)
adding: test/services.zip (stored 0%)
3、排除压缩文件
[root@localhost ~]# zip -r test.zip ./test -x test/services.zip test/services
updating: test/ (stored 0%)
updating: test/test_01.txt (stored 0%)
updating: test/test_02.txt (stored 0%)
updating: test/test_03.txt (stored 0%)
updating: test/test_04.txt (stored 0%)
updating: test/test_05.txt (stored 0%)
updating: test/test_06.txt (stored 0%)
updating: test/test_07.txt (stored 0%)
updating: test/test_08.txt (stored 0%)
updating: test/test_09.txt (stored 0%)
updating: test/test_10.txt (stored 0%)
updating: test/test_11.txt (stored 0%)
updating: test/test_12.txt (stored 0%)
updating: test/test.txt (stored 0%)