zip打包,unzip解包

本文详细介绍了zip和unzip命令的使用方法,包括如何压缩文件、打包文件、添加评论、更新已有文件、指定后缀名、以及如何解压文件、选择性解压部分文件等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、简单描述

zip用于压缩文件并将文件打包。

unzip与zip相反,解包并解压缩。

2、通过例子说明zip使用方法

(1)、zip命令的使用格式大致是这样的:

zip zipfile file1 file2 file3

以上命令是将file1,file2,file3三个文件先压缩,然后再将这三个压缩后的文件打包到zipfile.zip文件中。

(2)、关于打包后的后缀

zip zipfile.txt file1 file2 file3

以上命令将file1,file2,file3三个文件先压缩,然后再将这三个压缩后的文件打包到zipfile.txt文件中。

(3)打包后原文件是否存留

zip -m zipfile file1 file2 file3

以上命令打包后file1,file2,file3文件已经不存在了,因为选项-m的作用。假如没有-m选项,打包后原文件仍存留。

(4)向打包后的文档中加入评论

zip -z zipfile file1 file2 file3

以上命令执行后,终端会提示你加入评论信息,加入即可。对加入的评论信息,unzip解包时可以查看。

(5)向包中加入包中已有的包会怎样

zip zipfile file1

以上命令执行时,如果zipfile或zipfile.zip已经存在,且其中已经包含file1文件,那么以上命令会更新zipfile包中的file1文件。

还有很多选项,这里不一一介绍,将zip使用文档中的内容粘贴到下面:

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.
  If zipfile and list are omitted, zip compresses stdin to stdout.
  -f   freshen: only changed files  -u   update: only changed or new files
  -d   delete entries in zipfile    -m   move into zipfile (delete files)
  -r   recurse into directories     -j   junk (don't record) directory names
  -0   store only                   -l   convert LF to CR LF (-ll CR LF to LF)
  -1   compress faster              -9   compress better
  -q   quiet operation              -v   verbose operation/print version info
  -c   add one-line comments        -z   add zipfile comment
  -@   read names from stdin        -o   make zipfile as old as latest entry
  -x   exclude the following names  -i   include only the following names
  -F   fix zipfile (-FF try harder) -D   do not add directory entries
  -A   adjust self-extracting exe   -J   junk zipfile prefix (unzipsfx)
  -T   test zipfile integrity       -X   eXclude eXtra file attributes
  -y   store symbolic links as the link instead of the referenced file
  -R   PKZIP recursion (see manual)
  -e   encrypt                      -n   don't compress these suffixes

3、unzip的使用

(1)、unzip的使用方法大概是这样的

unzip zipfile.zip

以上命令,将zipfile.zip包解包,并且将其中的文件解压缩。

(2)只解压出一部分文件

unzip zipfile.zip file1 file2

无论zipfile包中有多少个文件,以上命令只解压出file1,file2两个文件。

(3)、查看压缩包中的评论信息

unzip -z zipfile

以上命令查看zipfile.zip包中的评论信息。这些评论信息是打包的时候用-z选项写进去的。

这里对unzip命令的选项不一一介绍,下面粘贴unzip使用文档中的描述:

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).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment
  -x  exclude files that follow (in xlist)   -d  extract files into exdir

modifiers:                                   -q  quiet mode (-qq => quieter)
  -n  never overwrite existing files         -a  auto-convert any text files
  -o  overwrite files WITHOUT prompting      -aa treat ALL files as text
  -j  junk paths (do not make directories)   -v  be verbose/print version info
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
Examples (see unzip.txt for more info):
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值