当前位置: 首页 > 工具软件 > p7zip > 使用案例 >

p7zip使用实例

刘浩思
2023-12-01

以下是CentOS77za的使用实例,CentOS下安装p7zip可以参考此文

[root@localhost ~]# 7za

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU x64)

Usage: 7za <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

压缩文档

[root@localhost oneinstack]# du -sh     ##当前目录大小
1.8M    .
[root@localhost oneinstack]# 7za a oi.7z *   ##将当前目录所有文件压缩保存为oi.7z

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU x64)

Scanning the drive:
7 folders, 128 files, 1541017 bytes (1505 KiB)

Creating archive: oi.7z

Items to compress: 135


Files read from disk: 128
Archive size: 131726 bytes (129 KiB)
Everything is Ok
[root@localhost oneinstack]# ls -lh oi.7z  ###压缩后大小
-rw-r--r-- 1 root root 129K Jun 16 15:59 oi.7z

p7zip默认使用7z格式,当然它还支持一些通用的压缩格式,如7z, lzma, cab, zip, gzip, bzip2, Z 和tar等等……

解压缩

解压缩有两个参数可用,ex

  • e 解压到当前目录,不使用压缩包的目录名
[root@localhost test]# 7za -e mx9.7z
[root@localhost test]# tree
.
├── gor
├── gor.exe
├── linux32
├── linux64
├── linuxarm
├── mx9.7z
├── win32
└── win64
  • x 按照压缩包内文档结构进行解压,一般这个使用这个参数较多
[root@localhost test]# 7za x mx9.7z
[root@localhost test]# tree .
.
├── gor370
│   ├── linux32
│   │   └── gor
│   ├── linux64
│   ├── linuxarm
│   │   └── gor
│   ├── win32
│   │   └── gor.exe
│   └── win64
│       └── gor.exe
└── mx9.7z

格式设置

使用-t参数来指定压缩格式,使用如下:

7z a -tzip archive.zip *.txt

将当前目录下所有txt文件打包压缩为archive.zip

7z t -t7z.split archive.7z.001

测试archive.7z.001中的所有文件,同时还支持多7z存档。

7z x -t# sfxarchive.exe

使用解析模式提取sfxarchive.exe文件

7z x -tiso archive.iso

ISO存档模式解压archive.iso文件

7z x -tudf archive.iso

UDF存档模式解压archive.iso文件,UDF说明在此

压缩模式设置

使用-m参数来设置模式,此项设置与文档类型有关。

7z类型的压缩模式参数:

  • -mx 设置压缩级别,x=[0 | 1 | 3 | 5 | 7 | 9 ]
等级模式字典FastBytesMatchFinderFilter说明
0Copy无压缩
1LZMA264 KB32HC4BCJ最快压缩
3LZMA21 MB32HC4BCJk快速压缩
5LZMA216 MB32BT4BCJ一般压缩
7LZMA232 MB64BT4BCJz最大压缩
9LZMA264 MB64BT4BCJ2j极致压缩

实例如下

[root@localhost ~]#7za -mx=0 a mx0.7z gor370/*
[root@localhost ~]#7za -mx=1 a mx1.7z gor370/*
[root@localhost ~]#7za -mx=3 a mx3.7z gor370/*
[root@localhost ~]#7za -mx=5 a mx5.7z gor370/*
[root@localhost ~]#7za -mx=7 a mx7.7z gor370/*
[root@localhost ~]#7za -mx=9 a mx9.7z gor370/*
[root@localhost ~]# du -sh gor370/
31M     gor370/
[root@localhost ~]# ls -lh m*.7z
-rw-r--r-- 1 root root  31M Jun 16 16:34 mx0.7z
-rw-r--r-- 1 root root 8.0M Jun 16 16:34 mx1.7z
-rw-r--r-- 1 root root 7.8M Jun 16 16:34 mx3.7z
-rw-r--r-- 1 root root 6.6M Jun 16 16:34 mx5.7z
-rw-r--r-- 1 root root 6.5M Jun 16 16:35 mx7.7z
-rw-r--r-- 1 root root 6.4M Jun 16 16:35 mx9.7z

可以看出压缩级别越高,压缩后的文件体积越小。

转载于:https://my.oschina.net/wrchiu/blog/968506

 类似资料: