手机版
你好,游客 登录 注册
背景:
阅读新闻

Linux zip命令:压缩文件或目录

[日期:2017-05-16] 来源:Linux社区  作者:Linux [字体:大 中 小]

".zip"是 Windows 中最常用的压缩格式,Linux 也可以正确识别".zip"格式,这可以方便地和 Windows 系统通用压缩文件。

".zip"格式文件的压缩命令就是 zip,其基本信息如下。

  • 命令名称:zip。
  • 英文原意:package and compress(archive)files。
  • 所在路径:/usr/bin/zip。
  • 执行权限:所有用户。
  • 功能描述:压缩文件或目录。

命令格式

[root@localhost ~]#zip [选项] 压缩包名 源文件或源目录

选项:

  • -r:压缩目录


zip 压缩命令需要手工指定压缩之后的压缩包名,注意写清楚扩展名,以便解压缩时使用。举个例子:

[root@localhost ~]# zip ana.zip anaconda-ks.cfg
adding: anaconda-ks.cfg (deflated 37%)
#压缩
[root@localhost ~]# ll ana.zip
-rw-r--r-- 1 root root 935 6月 1716:00 ana.zip
#压缩文件生成


所有的压缩命令都可以同时压缩多个文件,例如:

[root@localhost ~]# zip test.zip install.log install.log.syslog
adding: install.log (deflated 72%)
adding: install.log.syslog (deflated 85%)
#同时压缩多个文件到test.zip压缩包中
[root@localhost ~]#ll test.zip
-rw-r--r-- 1 root root 8368 6月 1716:03 test.zip
#压缩文件生成


如果想要压缩目录,则需要使用"-r"选项,例如:

[root@localhost ~]# mkdir dir1
#建立测试目录
[root@localhost ~]# zip -r dir1.zip dir1
adding: dir1/(stored 0%)
#压缩目录
[root@localhost ~]# ls -dl dir1.zip
-rw-r--r-- 1 root root 160 6月 1716:22 dir1.zip
#压缩文件生成

linux
相关资讯       Linux zip命令 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款