p7zip使用实例
2017-06-16 16:45
113 查看
以下是CentOS7中7za的使用实例,CentOS下安装p7zip可以参考此文
p7zip默认使用7z格式,当然它还支持一些通用的压缩格式,如7z, lzma, cab, zip, gzip, bzip2, Z 和tar等等……
将当前目录下所有txt文件打包压缩为archive.zip
测试archive.7z.001中的所有文件,同时还支持多7z存档。
使用解析模式提取sfxarchive.exe文件
以ISO存档模式解压archive.iso文件
以UDF存档模式解压archive.iso文件,UDF说明在此
7z类型的压缩模式参数:
实例如下
可以看出压缩级别越高,压缩后的文件体积越小。
[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 : 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等等……
解压缩
解压缩有两个参数可用,e和
x
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 ]
等级 | 模式 | 字典 | 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 | 极致压缩 |
[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
可以看出压缩级别越高,压缩后的文件体积越小。
相关文章推荐
- Android 使用mediaplayer播放res/raw文件夹中的音乐的实例
- yii2框架中使用下拉菜单的自动搜索yii-widget-select2实例分析
- netlink机制使用实例
- group by rollup 和grouping的使用实例
- video4linux(v4l)使用摄像头的实例基础教程与体会(四)
- Cocos2d-x3.1中ClippingNode的使用实例
- aggregate使用实例
- 【软件自动化测试-QTP实战技能 1】== 使用技巧实例
- CMake简介及使用实例
- Android多级列表ExpandableListView使用实例
- makefile 使用实例(二)
- JSF标签的使用实例
- makefile 模板使用 c语言具体实例 honker
- 使用Aspose.Cells组件生成Excel文件实例
- JDK 1.5 新功能使用实例之Generics (转)
- OpenStack详细解读:定义,好处与使用实例(1)
- android开发实例-TabHost的使用
- httpclient使用实例
- SQL SERVER 2008安装的时候提示“该实例名称已在使用”解决办法。
- java 使用JDBC构建简单的数据访问层实例详解