曲径通幽论坛

标题: zip/unzip -- zip 格式压缩/解压缩工具 [打印本页]

作者: beyes    时间: 2012-4-11 23:27
标题: zip/unzip -- zip 格式压缩/解压缩工具
zip 压缩非常流行,不像 gzip 和 bzip2 那样通常用在 Linux 上,它在多种平台上都有使用。一般使用格式是:
# zip nohup.out.zip nohup.out
  adding: nohup.out (deflated 94%)
# ls -l nohup.out*
-rw------- 1 root root 195515 2011-05-28 nohup.out
-rw-r--r-- 1 root root  12681 04-11 10:55 nohup.out.zip

使用 -r 选项递归压缩目录
# zip -r command.zip command/ delay.sh
  adding: command/ (stored 0%)
  adding: command/ver.patch (deflated 33%)
  adding: command/hello.c (deflated 24%)
... ...
  adding: command/ver1.txt (deflated 23%)
  adding: command/cut/ (stored 0%)
  adding: command/cut/temp.txt (deflated 70%)
  adding: delay.sh (deflated 25%)

解压缩 zip 包使用 unzip 命令,如:
unzip command.zip
不像 gunzip 和 unlzma 那样,在解压缩后会删除掉压缩包,unzip 解压缩后仍然保留压缩包。

可以用 unzip 的 -l 选项查看压缩包中的文件:
# unzip -l command.zip
Archive:  command.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2012-04-05 12:12   command/
      178  2012-04-03 12:15   command/ver.patch
      122  2012-04-03 21:19   command/hello.c
        0  2012-04-05 22:25   command/paste/
       10  2012-04-05 12:13   command/paste/3.txt
      113  2012-04-05 22:11   command/paste/iterline.sh
       82  2012-04-05 22:25   command/paste/tmp2.sh
       97  2012-04-05 22:15   command/paste/tmp.sh
       42  2012-04-05 12:22   command/paste/mulword.txt
       10  2012-04-05 12:13   command/paste/1.txt
       10  2012-04-05 12:13   command/paste/2.txt
       35  2012-04-03 10:08   command/ver2.txt
       35  2012-04-03 12:15   command/ver1.txt
        0  2012-04-04 09:48   command/cut/
      108  2012-04-04 09:48   command/cut/temp.txt
      170  2012-03-21 13:57   delay.sh
---------                     -------
     1012                     16 files

如果要从 zip 包中删除一个文件,那么可以用 -d 选项,如:
# zip -d command.zip delay.sh
deleting: delay.sh

如果要更新压缩包中的文件,那么可用 -u 选项:
$ zip file.zip -u newfile





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2