【Linux】压缩与解压zip

  • 1、背景
  • 2、zip压缩
  • 3、unzip解压

1、背景

zip是工作中最常见的一种压缩格式。
本博客介绍在linux下的使用。

2、zip压缩

打印zip的使用说明:

root@iZutmw06cp2Z:~# zip --help
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
Zip 3.0 (July 5th 2008). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]The default action is to add or replace zipfile entries from list, whichcan 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 OS 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-e   encrypt                      -n   don't compress these suffixes-h2  show more helproot@iZutmw06cp2Z:~#

功能很多,常用的使用示例:
示例1,将指定目录/to_be_zip压缩成test.zip文件:

 zip -r test.zip /to_be_zip

3、unzip解压

打印unzip的使用说明:

root@iZutmw06cp2Z:~# unzip -hhExtended Help for UnZipSee the UnZip Manual for more detailed helpUnZip lists and extracts files in zip archives.  The default action is to
extract zipfile entries to the current directory, creating directories as
needed.  With appropriate options, UnZip lists the contents of archives
instead.Basic unzip command line:unzip [-Z] options archive[.zip] [file ...] [-x xfile ...] [-d exdir]Some examples:unzip -l foo.zip        - list files in short format in archive foo.zipunzip -t foo            - test the files in archive foounzip -Z foo            - list files using more detailed zipinfo formatunzip foo               - unzip the contents of foo in current dirunzip -a foo            - unzip foo and convert text files to local OSIf unzip is run in zipinfo mode, a more detailed list of archive contents
is provided.  The -Z option sets zipinfo mode and changes the available
options.Basic zipinfo command line:zipinfo options archive[.zip] [file ...] [-x xfile ...]unzip -Z options archive[.zip] [file ...] [-x xfile ...]Below, Mac OS refers to Mac OS before Mac OS X.  Mac OS X is a Unix based
port and is referred to as Unix Apple.unzip options:-Z   Switch to zipinfo mode.  Must be first option.-hh  Display extended help.-A   [OS/2, Unix DLL] Print extended help for DLL.-c   Extract files to stdout/screen.  As -p but include names.  Also,-a allowed and EBCDIC conversions done if needed.-f   Freshen by extracting only if older file on disk.-l   List files using short form.-p   Extract files to pipe (stdout).  Only file data is output and allfiles extracted in binary mode (as stored).-t   Test archive files.-T   Set timestamp on archive(s) to that of newest file.  Similar tozip -o but faster.-u   Update existing older files on disk as -f and extract new files.-v   Use verbose list format.  If given alone as unzip -v show versioninformation.  Also can be added to other list commands for moreverbose output.-z   Display only archive comment.unzip modifiers:-a   Convert text files to local OS format.  Convert line ends, EOFmarker, and from or to EBCDIC character set as needed.-b   Treat all files as binary.  [Tandem] Force filecode 180 ('C').[VMS] Autoconvert binary files.  -bb forces convert of all files.-B   [UNIXBACKUP compile option enabled] Save a backup copy of eachoverwritten file in foo~ or foo~99999 format.-C   Use case-insensitive matching.-D   Skip restoration of timestamps for extracted directories.  On VMS thisis on by default and -D essentially becames -DD.-DD  Skip restoration of timestamps for all entries.-E   [MacOS (not Unix Apple)]  Display contents of MacOS extra field duringrestore.-F   [Acorn] Suppress removal of NFS filetype extension.  [Non-Acorn ifACORN_FTYPE_NFS] Translate filetype and append to name.-i   [MacOS] Ignore filenames in MacOS extra field.  Instead, use name instandard header.-j   Junk paths and deposit all files in extraction directory.-J   [BeOS] Junk file attributes.  [MacOS] Ignore MacOS specific info.-K   [AtheOS, BeOS, Unix] Restore SUID/SGID/Tacky file attributes.-L   Convert to lowercase any names from uppercase only file system.-LL  Convert all files to lowercase.-M   Pipe all output through internal pager similar to Unix more(1).-n   Never overwrite existing files.  Skip extracting that file, no prompt.-N   [Amiga] Extract file comments as Amiga filenotes.-o   Overwrite existing files without prompting.  Useful with -f.  Use withcare.-P p Use password p to decrypt files.  THIS IS INSECURE!  Some OS showcommand line to other users.-q   Perform operations quietly.  The more q (as in -qq) the quieter.-s   [OS/2, NT, MS-DOS] Convert spaces in filenames to underscores.-S   [VMS] Convert text files (-a, -aa) into Stream_LF format.-U   [UNICODE enabled] Show non-local characters as #Uxxxx or #Lxxxxxx ASCIItext escapes where x is hex digit.  [Old] -U used to leave namesuppercase if created on MS-DOS, VMS, etc.  See -L.-UU  [UNICODE enabled] Disable use of stored UTF-8 paths.  Note that UTF-8paths stored as native local paths are still processed as Unicode.-V   Retain VMS file version numbers.-W   [Only if WILD_STOP_AT_DIR] Modify pattern matching so ? and * do notmatch directory separator /, but ** does.  Allows matching at specificdirectory levels.-X   [VMS, Unix, OS/2, NT, Tandem] Restore UICs and ACL entries under VMS,or UIDs/GIDs under Unix, or ACLs under certain network-enabledversions of OS/2, or security ACLs under Windows NT.  Can requireuser privileges.-XX  [NT] Extract NT security ACLs after trying to enable additionalsystem privileges.-Y   [VMS] Treat archived name endings of .nnn as VMS version numbers.-$   [MS-DOS, OS/2, NT] Restore volume label if extraction medium isremovable.  -$$ allows fixed media (hard drives) to be labeled.-/ e [Acorn] Use e as extension list.-:   [All but Acorn, VM/CMS, MVS, Tandem] Allow extract archive members intolocations outside of current extraction root folder.  This allowspaths such as ../foo to be extracted above the current extractiondirectory, which can be a security problem.-^   [Unix] Allow control characters in names of extracted entries.  Usuallythis is not a good thing and should be avoided.-2   [VMS] Force unconditional conversion of names to ODS-compatible names.Default is to exploit destination file system, preserving cases andextended name characters on ODS5 and applying ODS2 filtering on ODS2.Wildcards:Internally unzip supports the following wildcards:?       (or %% or #, depending on OS) matches any single character*       matches any number of characters, including zero[list]  matches char in list (regex), can do range [ac-f], all but [!bf]If port supports [], must escape [ as [[]For shells that expand wildcards, escape (\* or "*") so unzip can recurse.Include and Exclude:-i pattern pattern ...   include files that match a pattern-x pattern pattern ...   exclude files that match a patternPatterns are paths with optional wildcards and match paths as stored inarchive.  Exclude and include lists end at next option or end of line.unzip archive -x pattern pattern ...Multi-part (split) archives (archives created as a set of split files):Currently split archives are not readable by unzip.  A workaround isto use zip to convert the split archive to a single-file archive anduse unzip on that.  See the manual page for Zip 3.0 or later.Streaming (piping into unzip):Currently unzip does not support streaming.  The funzip utility can beused to process the first entry in a stream.cat archive | funzipTesting archives:-t        test contents of archiveThis can be modified using -q for quieter operation, and -qq for evenquieter operation.Unicode:If compiled with Unicode support, unzip automatically handles archiveswith Unicode entries.  Currently Unicode on Win32 systems is limited.Characters not in the current character set are shown as ASCII escapesin the form #Uxxxx where the Unicode character number fits in 16 bits,or #Lxxxxxx where it doesn't, where x is the ASCII character for a hexdigit.zipinfo options (these are used in zipinfo mode (unzip -Z ...)):-1  List names only, one per line.  No headers/trailers.  Good for scripts.-2  List names only as -1, but include headers, trailers, and comments.-s  List archive entries in short Unix ls -l format.  Default list format.-m  List in long Unix ls -l format.  As -s, but includes compression %.-l  List in long Unix ls -l format.  As -m, but compression in bytes.-v  List zipfile information in verbose, multi-page format.-h  List header line.  Includes archive name, actual size, total files.-M  Pipe all output through internal pager similar to Unix more(1) command.-t  List totals for files listed or for all files.  Includes uncompressedand compressed sizes, and compression factors.-T  Print file dates and times in a sortable decimal format (yymmdd.hhmmss)Default date and time format is a more human-readable version.-U  [UNICODE] If entry has a UTF-8 Unicode path, display any charactersnot in current character set as text #Uxxxx and #Lxxxxxx escapesrepresenting the Unicode character number of the character in hex.-UU [UNICODE]  Disable use of any UTF-8 path information.-z  Include archive comment if any in listing.funzip stream extractor:funzip extracts the first member in an archive to stdout.  Typicallyused to unzip the first member of a stream or pipe.  If a file argumentis given, read from that file instead of stdin.funzip command line:funzip [-password] [input[.zip|.gz]]unzipsfx self extractor:Self-extracting archives made with unzipsfx are no more (or less)portable across different operating systems than unzip executables.In general, a self-extracting archive made on a particular Unix system,for example, will only self-extract under the same flavor of Unix.Regular unzip may still be used to extract embedded archive however.unzipsfx command line:<unzipsfx+archive_filename>  [-options] [file(s) ... [-x xfile(s) ...]]unzipsfx options:-c, -p - Output to pipe.  (See above for unzip.)-f, -u - Freshen and Update, as for unzip.-t     - Test embedded archive.  (Can be used to list contents.)-z     - Print archive comment.  (See unzip above.)unzipsfx modifiers:Most unzip modifiers are supported.  These include-a     - Convert text files.-n     - Never overwrite.-o     - Overwrite without prompting.-q     - Quiet operation.-C     - Match names case-insensitively.-j     - Junk paths.-V     - Keep version numbers.-s     - Convert spaces to underscores.-$     - Restore volume label.If unzipsfx compiled with SFX_EXDIR defined, -d option also available:-d exd - Extract to directory exd.
By default, all files extracted to current directory.  This option
forces extraction to specified directory.See unzipsfx manual page for more information.root@iZutmw06cp2Z:~#

功能很多,常用的使用示例:
示例1,将压缩文件test.zip在当前目录下解压缩:

 unzip test.zip

示例2,将压缩文件test.zip在指定目录yus下解压缩,
如果已有相同的文件存在,要求unzip命令覆盖原先的文件。

unzip -o test.zip -d ./yus/

【Linux】压缩与解压zip相关推荐

  1. linux 压缩7z文件夹,Linux 下压缩与解压.zip和.rar及.7z文件

    Linux 下压缩与解压.zip和.rar及.7z文件对于Window下的常见压缩文件.zip和.rar,Linux也有相应的方法来解压它们: 1)对于.zip linux下提供了zip和unzip程 ...

  2. 解压安装包linux,Linux 下载安装 rar 并解压rar压缩包(Linux下如何解压.zip和.ra

    Linux 下载安装 rar 并解压rar压缩包(Linux下如何解压.zip和.ra Linux 下载安装 rar 并解压rar压缩包(Linux下如何解压.zip和.rar文件) Linux下如何 ...

  3. Linux 下载安装 rar 并解压rar压缩包(Linux下如何解压.zip和.rar文件)

    Linux下如何解压.zip和.rar文件,对于Window下的常见压缩文件.zip和.rar,Linux也有相应的方法来解压它们: 1)对于zip linux下提供了zip和unzip程序,zip是 ...

  4. linux用unzip解压.zip文件失败解决方案

    linux用unzip解压.zip文件失败解决方案 问题描述 在服务器上下载数据集之后进行解压,一般来说用unzip指令去解压.zip文件,有时候解压的时候会出现错误提示: unzip: cannot ...

  5. 【全网最全】一文搞定 Linux 压缩、解压哪些事儿

    一文搞定 Linux 压缩.解压哪些事儿 Linux 常用的解压和压缩命令如下: 1..tar # 解包 tar xvf FileName.tar # 打包 tar cvf FileName.tar ...

  6. Linux服务器中解压zip包

    Linux服务器中解压zip包 Linux下解压zip文件,就一个命令行. Unzip [文件名] 示例: unzip {you file name} 我现在要解压datamaster.zip这个文件 ...

  7. Linux 压缩、解压、打包操作

    文章目录 tar 打包/压缩 解压 gzip 压缩 解压 zip 压缩 解压 总结 在Linux 中,解压.压缩.打包是日常会很频繁用到的几个操作,但是因为参数很多,没有记忆点,加上压缩文件的类型很多 ...

  8. linux快速解压缩,快速了解linux压缩与解压

    旨在快速了解linux文档压缩与解压,如需详细理解某个命令可用man一下,或者google一下. GUN-zip(gz) 压缩:gzip testfile       #压缩testfile文件,生成 ...

  9. Linux压缩|解压_CodingPark编程公园

    文章介绍 本文主要介绍: Linux的基础参数 Linux压缩 Linux解压缩 基础参数 tar - 5大参数 -c:压缩 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原 ...

最新文章

  1. java笔记 -- 输入输出
  2. 十进制中正整数N中1的个数(2)
  3. IDEA热布署报错java.lang.IllegalStateException: Restarter has not been initialized
  4. 阿里云发布勒索病毒专杀工具:一键修复 彻底查杀
  5. 【Breadth-first Search 】515. Find Largest Value in Each Tree Row
  6. 【图像算法】彩色图像分割专题五:提取彩色图像上特定色彩
  7. LeetCode 1679. K 和数对的最大数目(哈希)
  8. access制作封装软件_用Access开发《社工服务管理系统》
  9. 互联网+大赛作品_【快讯】智物联获第二届中国工业互联网大赛优秀作品奖
  10. RecyclerView之自定义LayoutManager和SnapHelper
  11. 金融数据分析之财务分析表要填数据怎么办?(学习理财课程后开发的助手工具)
  12. 社会我张哥,人狠话不多。
  13. python3 urlencode_Python3 parse.urlencode() 与parse.unquote()
  14. 经典的广告词及其翻译
  15. pytorch多进程加速及代码优化
  16. 为什么计算机能读懂 1 和 0 ?
  17. python中的path的使用
  18. 舒舍 舍友的北漂租房故事
  19. cml sml区别_CML与SML有何联系和区别?
  20. Andorid.bp文件和Anorid.rc文件入门

热门文章

  1. 人工智能--语义网络表示法
  2. 关于群晖 transmission安装及汉化
  3. osg demo14 漫游
  4. 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系
  5. Java基础-类的封装,成员变量的访问及隐藏
  6. 西电计算机初试复试占比,西安电子科技大学考研初试、考研复试成绩占比
  7. html5的基本工作原理,HTML5基础开发教程
  8. android+祖玛游戏源码,unity祖玛游戏Zuma Ball Blast源码
  9. Java命名规范--阿呆
  10. Wikipedia iOS客户端源码