p7zip
7zip - Linux/Posix 平台的命令行移植版本。
p7zip是移植到POSIX/Unix-like系统的7-Zip软件,可以压缩解压7z格式的文件。常用命令包括7z和7za,通过参数调整压缩解压设置。其支持的系统包括但不限于Linux内核的Debian、Fedora、Gentoo Linux、AltLinux.org,非Linux内核的FreeBSD、Mac OS X、iOS(越狱后可安装)、BeOS、FreeDOS、AmigaOS等。
从4.10开始,p7zip (7-zip)支持little-endian和big-endian。
安装p7zip
通过源码安装
Linux下最好使用源码进行安装,各发行版通用,安装过程如下:
1wget https://sourceforge.net/projects/p7zip/files/p7zip/16.02/p7zip_16.02_src_all.tar.bz2
2tar jxf p7zip_16.02_src_all.tar.bz2
3cd p7zip_16.02
4make
5make install
Debian/Ubuntu(apt系)
使用apt-get install p7zip-full进行安装即可。
CentOS/Fedora/RHEL(rpm系)
rpm包下载地址http://rpmfind.net/linux/rpm2html/search.php?query=p7zip(x86-64), 下载后使用rpm -ivh p7zip-17.04-3.mga9.x86_64.rpm来安装。
p7zip使用实例
- 压缩文档
1[root@localhost oneinstack]# du -sh ##当前目录大小
21.8M .
3[root@localhost oneinstack]# 7za a oi.7z * ##将当前目录所有文件压缩保存为oi.7z
47-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
5p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU x64)
6Scanning the drive:
77 folders, 128 files, 1541017 bytes (1505 KiB)
8Creating archive: oi.7z
9Items to compress: 135
10Files read from disk: 128
11Archive size: 131726 bytes (129 KiB)
12Everything is Ok
13[root@localhost oneinstack]# ls -lh oi.7z ###压缩后大小
14-rw-r--r-- 1 root root 129K Jun 16 15:59 oi.7z
p7zip默认使用7z格式,当然它还支持一些通用的压缩格式,如7z, lzma, cab, zip, gzip, bzip2, Z 和tar等等……
- 解压缩文档 解压缩有两个参数可用,e和x
e解压到当前目录,不使用压缩包的目录名
1[root@localhost test]# 7za -e mx9.7z
2[root@localhost test]# tree
3.
4├── gor
5├── gor.exe
6├── linux32
7├── linux64
8├── linuxarm
9├── mx9.7z
10├── win32
11└── win64
x按照压缩包内文档结构进行解压,一般这个使用这个参数较多
1[root@localhost test]# 7za x mx9.7z
2[root@localhost test]# tree .
3.
4├── gor370
5│ ├── linux32
6│ │ └── gor
7│ ├── linux64
8│ ├── linuxarm
9│ │ └── gor
10│ ├── win32
11│ │ └── gor.exe
12│ └── win64
13│ └── gor.exe
14└── mx9.7z
- 格式设置
使用-t参数来指定压缩格式,使用如下:
17z a -tzip archive.zip *.txt
将当前目录下所有txt文件打包压缩为archive.zip
17z t -t7z.split archive.7z.001
测试archive.7z.001中的所有文件,同时还支持多7z存档。
17z x -t# sfxarchive.exe
使用解析模式提取sfxarchive.exe文件
17z x -tiso archive.iso
以ISO存档模式解压archive.iso文件
17z x -tudf archive.iso
以UDF存档模式解压archive.iso文件,UDF说明在此https://en.wikipedia.org/wiki/Universal_Disk_Format
- 压缩模式设置 使用-m参数来设置模式,此项设置与文档类型有关。
7z类型的压缩模式参数:
-mx 设置压缩级别,x=[0 | 1 | 3 | 5 | 7 | 9 ] 等级 模式 字典 FastBytes MatchFinder Filter 说明 0 Copy 无压缩 1 LZMA2 64 KB 32 HC4 BCJ 最快压缩 3 LZMA2 1 MB 32 HC4 BCJk 快速压缩 5 LZMA2 16 MB 32 BT4 BCJ 一般压缩 7 LZMA2 32 MB 64 BT4 BCJz 最大压缩 9 LZMA2 64 MB 64 BT4 BCJ2j 极致压缩
实例如下
1[root@localhost ~]#7za -mx=0 a mx0.7z gor370/*
2[root@localhost ~]#7za -mx=1 a mx1.7z gor370/*
3[root@localhost ~]#7za -mx=3 a mx3.7z gor370/*
4[root@localhost ~]#7za -mx=5 a mx5.7z gor370/*
5[root@localhost ~]#7za -mx=7 a mx7.7z gor370/*
6[root@localhost ~]#7za -mx=9 a mx9.7z gor370/*
7[root@localhost ~]# du -sh gor370/
831M gor370/
9[root@localhost ~]# ls -lh m*.7z
10-rw-r--r-- 1 root root 31M Jun 16 16:34 mx0.7z
11-rw-r--r-- 1 root root 8.0M Jun 16 16:34 mx1.7z
12-rw-r--r-- 1 root root 7.8M Jun 16 16:34 mx3.7z
13-rw-r--r-- 1 root root 6.6M Jun 16 16:34 mx5.7z
14-rw-r--r-- 1 root root 6.5M Jun 16 16:35 mx7.7z
15-rw-r--r-- 1 root root 6.4M Jun 16 16:35 mx9.7z
可以看出压缩级别越高,压缩后的文件体积越小。
7za命令帮助
17-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
2p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU QEMU Virtual CPU version (cpu64-rhel6) (6D3),ASM,AES-NI)
3Usage: 7z [...] [...]
4 [<@listfiles...>]
5
6 a : Add files to archive
7 b : Benchmark
8 d : Delete files from archive
9 e : Extract files from archive (without using directory names)
10 h : Calculate hash values for files
11 i : Show information about supported formats
12 l : List contents of archive
13 rn : Rename files in archive
14 t : Test integrity of archive
15 u : Update files to archive
16 x : eXtract files with full paths
17
18 -- : Stop switches parsing
19 -ai[r[-|0]]{@listfile|!wildcard} : Include archives
20 -ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
21 -ao{a|s|t|u} : set Overwrite mode
22 -an : disable archive_name field
23 -bb[0-3] : set output log level
24 -bd : disable progress indicator
25 -bs{o|e|p}{0|1|2} : set output stream for output/error/progress line
26 -bt : show execution time statistics
27 -i[r[-|0]]{@listfile|!wildcard} : Include filenames
28 -m{Parameters} : set compression Method
29 -mmt[N] : set number of CPU threads
30 -o{Directory} : set Output directory
31 -p{Password} : set Password
32 -r[-|0] : Recurse subdirectories
33 -sa{a|e|s} : set Archive name mode
34 -scc{UTF-8|WIN|DOS} : set charset for for console input/output
35 -scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files
36 -scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands
37 -sdel : delete files after compression
38 -seml[.] : send archive by email
39 -sfx[{name}] : Create SFX archive
40 -si[{name}] : read data from stdin
41 -slp : set Large Pages mode
42 -slt : show technical information for l (List) command
43 -snh : store hard links as links
44 -snl : store symbolic links as links
45 -sni : store NT security information
46 -sns[-] : store NTFS alternate streams
47 -so : write data to stdout
48 -spd : disable wildcard matching for file names
49 -spe : eliminate duplication of root folder for extract command
50 -spf : use fully qualified file paths
51 -ssc[-] : set sensitive case mode
52 -ssw : compress shared files
53 -stl : set archive timestamp from the most recently modified file
54 -stm{HexMask} : set CPU thread affinity mask (hexadecimal number)
55 -stx{Type} : exclude archive type
56 -t{Type} : Set type of archive
57 -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options
58 -v{Size}[b|k|m|g] : Create volumes
59 -w[{path}] : assign Work directory. Empty path means a temporary directory
60 -x[r[-|0]]{@listfile|!wildcard} : eXclude filenames
61 -y : assume Yes on all queries