每天一个Linux命令:zip命令(压缩文件或文件夹为.zip文件)

zip命令用于压缩文件,将文件压缩为.zip文件。

语法:

zip [选项] [-P <密码>] [目标文件] [源文件/源目录]

...
# 更多的选项可以用 zip --help 来查看。

选项:

-r:递归处理,将指定目录下的所有文件和子目录一并处理。
-q:不显示指令执行过程。
-p[密码]:设置密码

实例:


# 实例一:压缩一个文件

[email protected]:~/test# zip test.zip test.txt
  adding: test.txt (stored 0%)


# 实例二:压缩多个文件

[email protected]:~/test# zip test2.zip test.txt test2.txt test3.txt
  adding: test.txt (stored 0%)
  adding: test2.txt (stored 0%)
  adding: test3.txt (stored 0%)


# 实例三:压缩一个目录(递归处理)

[email protected]:~/test# zip -r test3.zip test
  adding: test/ (stored 0%)
  adding: test/test.txt (stored 0%)
  adding: test/test2.txt (stored 0%)
  adding: test/test3.txt (stored 0%)


# 实例四:压缩多个目录(递归处理)

[email protected]:~/test# zip -r test3.zip test test2
updating: test/ (stored 0%)
updating: test/test.txt (stored 0%)
updating: test/test2.txt (stored 0%)
updating: test/test3.txt (stored 0%)
  adding: test2/ (stored 0%)
  adding: test2/test4.txt (stored 0%)
  adding: test2/test5.txt (stored 0%)
  adding: test2/test6.txt (stored 0%)


# 实例五:压缩多个文件夹和目录(递归处理)

[email protected]:~/test# zip -r test4.zip test test2 test.txt test2.txt test3.txt
  adding: test/ (stored 0%)
  adding: test/test.txt (stored 0%)
  adding: test/test2.txt (stored 0%)
  adding: test/test3.txt (stored 0%)
  adding: test2/ (stored 0%)
  adding: test2/test4.txt (stored 0%)
  adding: test2/test5.txt (stored 0%)
  adding: test2/test6.txt (stored 0%)
  adding: test.txt (stored 0%)
  adding: test2.txt (stored 0%)
  adding: test3.txt (stored 0%)


# 实例六:压缩多个文件夹和目录(递归处理,不显示指令执行过程)

[email protected]:~/test# zip -qr test4.zip test test2 test.txt test2.txt test3.txt


# 实例七:压缩多个文件夹和目录(递归处理,不显示指令执行过程,并设置密码)

[email protected]:~/test# zip -qr -P 1234 test4.zip test test2 test.txt test2.txt test3.txt
最后修改:2019 年 07 月 09 日 10 : 20 PM
如果觉得我的文章对你有用,请随意赞赏

发表评论