本文已参与「新人创作礼」活动,一起开启掘金创作之路。
一、命令详解
1.1【功能说明】
zip压缩格式是Windows与Linux等多平台通用的压缩格式。和gzip命令相比,zip命令压缩文件不仅不会删除源文件,而且还可以压缩目录。
1.2【语法格式】
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
The default action is to add or replace zipfile entries from list, which
can include the special name - to compress standard input.
Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
Default action is to extract files in list, except those in xlist, to exdir;
file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage).
1.3【选项说明】
zip参数选项说明
-r将指定目录下的所有文件和子目录一并压缩-x压缩文件时排除某个文件-q不显示压缩信息
unzip参数选项说明
-l不解压显示压缩包内容-d指定解压目录-o解压时不提示是否覆盖文件-v解压时显示详细信息
二、使用范例
2.1 压缩文件
# 准备要压缩的文件
cp /etc/services .
ll -h
# 压缩
zip services.zip ./services
ll -h
将/home/Blinux/html/这个目录下所有文件和文件夹打包为当前目录下的html.zip
zip -q -r html.zip /home/Blinux/html
上面的命令操作是将绝对地址的文件及文件夹进行压缩,以下给出压缩相对路径目录,比如目前在Blinux这个目录下
zip -q -r html.zip html
比如现在在html目录下,zip的压缩命令是
zip -q -r html.zip *
2.2 压缩目录
cd /
# 这样只压缩目录这一个文件,目录下的文件
zip tmp.zip ./tmp
# 使用-r选项递归压缩
zip -r tmp.zip ./tmp
2.3 排除压缩
zip -r tmp1.zip ./tmp -x tmp/test.log
2.4 查看压缩文件
unzip -l tmp.zip
2.5 解压文件
# 常规解压文件,如果源文件存在会提示是否替换
unzip tmp.zip
# 显示解压信息
unzip -v tmp.zip
# 指定解压目录
unzip -d /tmp tmp.zip
三、扩展知识
无
四、命令总结
- 2022/12/18 周末也要加班