You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4.6 KiB

7z

选项

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
       [<@listfiles...>]

<Commands>
  a : Add files to archive
  b : Benchmark
  d : Delete files from archive
  e : Extract files from archive (without using directory names)
  h : Calculate hash values for files
  i : Show information about supported formats
  l : List contents of archive
  rn : Rename files in archive
  t : Test integrity of archive
  u : Update files to archive
  x : eXtract files with full paths

<Switches>
  -- : Stop switches parsing
  -ai[r[-|0]]{@listfile|!wildcard} : Include archives
  -ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
  -ao{a|s|t|u} : set Overwrite mode
  -an : disable archive_name field
  -bb[0-3] : set output log level
  -bd : disable progress indicator
  -bs{o|e|p}{0|1|2} : set output stream for output/error/progress line
  -bt : show execution time statistics
  -i[r[-|0]]{@listfile|!wildcard} : Include filenames
  -m{Parameters} : set compression Method
    -mmt[N] : set number of CPU threads
  -o{Directory} : set Output directory
  -p{Password} : set Password
  -r[-|0] : Recurse subdirectories
  -sa{a|e|s} : set Archive name mode
  -scc{UTF-8|WIN|DOS} : set charset for for console input/output
  -scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files
  -scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands
  -sdel : delete files after compression
  -seml[.] : send archive by email
  -sfx[{name}] : Create SFX archive
  -si[{name}] : read data from stdin
  -slp : set Large Pages mode
  -slt : show technical information for l (List) command
  -snh : store hard links as links
  -snl : store symbolic links as links
  -sni : store NT security information
  -sns[-] : store NTFS alternate streams
  -so : write data to stdout
  -spd : disable wildcard matching for file names
  -spe : eliminate duplication of root folder for extract command
  -spf : use fully qualified file paths
  -ssc[-] : set sensitive case mode
  -ssw : compress shared files
  -stl : set archive timestamp from the most recently modified file
  -stm{HexMask} : set CPU thread affinity mask (hexadecimal number)
  -stx{Type} : exclude archive type
  -t{Type} : Set type of archive
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options
  -v{Size}[b|k|m|g] : Create volumes
  -w[{path}] : assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]{@listfile|!wildcard} : eXclude filenames
  -y : assume Yes on all queries

p7zip p7zip-plugins

支持的zip格式压缩方法

  • 0 - Store
  • 1 - Shrink (decompression only)
  • 6 - Implode (decompression only)
  • 8 - Deflate
  • 9 - Deflate64
  • 12 - BZip2
  • 14 - LZMA
  • 95 - xz (decompression only)
  • 98 - PPMd
  • 99 - WinZip AES

支持的7z格式压缩方法

压缩方法 描述
LZMA Improved and optimized version of LZ77 algorithm
LZMA2 LZMA-based compression method. It provides better multithreading support than LZMA
PPMD Dmitry Shkarin's PPMdH with small changes
BCJ Converter for 32-bit x86 executables
BCJ2 Converter for 32-bit x86 executables
BZip2 Standard BWT algorithm
Deflate Standard LZ77-based algorithm

退出码含义

Code Meaning
0 No error
1 Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
2 Fatal error
7 Command line error
8 Not enough memory for operation
255 User stopped the process

实例

7z a -r achive.7z /home   # 压缩home目录-r可以省略
7z e archive.7z -o/home    # 解压文件到home目录
7z x archive.7z             # 以完整路径解压文件
7z u archive.7z *.doc       # 更新所有doc文件并压缩到archive压缩包中
7z d -r archive.7z *.log    # 从压缩包删除文件,删除压缩包所有后缀为log文件
7z l archive.7z     # 列出压缩包中文件
7z t -r archive.7z *.doc    # 测试压缩包中的所有doc文件

# 7z压缩文件-t7z可以省略/root/achive.7z表示将压缩文件放到root目录下-m0=LZMA2 -mx表示以LZMA2算法等级是9(0-9)-aoa直
# 接覆盖现有文件,-mmt多线程(30个线程)加速压缩,-y默认允许所有-pSECRET表示密码是SECRET-bb3设置输出日志文件等级(0-3)
# -bsp1将命令输出写入到out.log文件
7z a -r -t7z /root/achive.7z /home -m0=LZMA2 -mx=9 -aoa -mmt=30 -y -pSECRET -bb3 -bsp1 > out.log

恢复损坏的7z压缩包

错误类型有两种:

  • 解压或测试时提示数据错误或CRC错误
  • 打开时,提示:文件'a.7z'作为存档无法打开