linux 中解压7z文件
更新时间:2017-03-26 00:13:50
linux 解压、解压7z文件方法
安装7z源[root@VM_18_10_centos ~]# sudo yum install p7zip p7zip-plugins
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Package p7zip-16.02-2.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package p7zip-plugins.x86_64 0:16.02-2.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================
Package Arch Version Repository Size
=============================================================================================
Installing:
p7zip-plugins x86_64 16.02-2.el6 epel 982 k
Transaction Summary
=============================================================================================
Install 1 Package(s)
Total download size: 982 k
Installed size: 2.7 M
Is this ok [y/N]: y
Downloading Packages:
p7zip-plugins-16.02-2.el6.x86_64.rpm | 982 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : p7zip-plugins-16.02-2.el6.x86_64 1/1
Verifying : p7zip-plugins-16.02-2.el6.x86_64 1/1
Installed:
p7zip-plugins.x86_64 0:16.02-2.el6
Complete!
[root@VM_18_10_centos ~]#
查看一下程序使用说明[root@VM_18_10_centos ~]# 7z
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C,Utf16=off,HugeFiles=on,64 bits,1 CPU Intel(R) Xeon(R) CPU E5-26xx v2 (306E4),ASM,AES-NI)
Usage: 7z [...] [...]
[]
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
-- : 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@VM_18_10_centos ~]#
7z命令解压文件的例子:
7z x "/2017-03-03-uploads.7z" -y -aoa -o/11
解压2017-03-03-uploads.7z文件到目录/11。
7z x "/2017-03-03-uploads.7z" -y -aoa -o/11
参数说明:
x:完整路径下解压文件
-y:所有确认选项都默认为是(即不出现确认提示)
-aoa:直接覆盖现有文件,而没有任何提示。
-o:设置输出目录[root@izp0w0bp7w7vul720hq98lz /]# 7z x "/2017-03-03-uploads.7z" -y -aoa -o/11
7-Zip [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,2 CPUs Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz (406F1),ASM,AES-NI)
Scanning the drive for archives:
1 file, 9218952819 bytes (8792 MiB)
Extracting archive: /2017-03-03-uploads.7z
--
Path = /2017-03-03-uploads.7z
Type = 7z
Physical Size = 9218952819
Headers Size = 1784480
Method = LZMA2:24
Solid = +
Blocks = 5
Everything is Ok
Folders: 2905
Files: 140185
Size: 10296563719
Compressed: 9218952819
[root@izp0w0bp7w7vul720hq98lz /]#
-t7z -- 压缩文件的格式为7z
-mx=9 -ms=200m -mf -mhc -mhcf -m0=LZMA:a=2:d=25:mf=bt4b:fb=64 -mmt
-- 指定压缩算法选项
-mx=9 -- 设置压缩等级为极限压缩(默认为:LZMA 最大算法、32 MB 字典大小、BT4b Match finder、单词大小为 64、BCJ2 过滤器)
-ms=200m -- 开启固实模式,设置固实数据流大小为200MB。
-mf -- 开启可执行文件压缩过滤器。
-mhc -- 开启档案文件头压缩。
-mhcf -- 开启档案文件头完全压缩。我所使用的7z版本为4.42>2.30。
-m0=LZMA:a=2:d=25:mf=bt4b:fb=64
-- 第一个备选压缩算法为LZMA,压缩等级为最大压缩,LZMA算法使用的字典大小为25(2MB的5次方)32MB,算法的匹配器为bt4b(所需要内存为d×9.5 + 34 MB),压缩算法的紧凑字节为最大模式的64字节。
-mmt -- 开启多线程模式。
-r-- 递归到所有的子目录。
7z命令压缩文件的例子:
7z a -t7z /huoniao-2017-03-26.7z /huoniao/ -mhcf -mmt -r[root@VM_18_10_centos huoniao]# 7z a -t7z /huoniao-2017-03-26.7z /huoniao/ -mhcf -mmt -r
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C,Utf16=off,HugeFiles=on,64 bits,1 CPU Intel(R) Xeon(R) CPU E5-26xx v2 (306E4),ASM,AES-NI)
Scanning the drive:
4929 folders, 152256 files, 11032296754 bytes (11 GiB)
Creating archive: /huoniao-2017-03-26.7z
Items to compress: 157185
Files read from disk: 152189
Archive size: 9688588793 bytes (9240 MiB)
Everything is Ok
[root@VM_18_10_centos huoniao]#
Connection closed by foreign host.
Disconnected from remote host(ikuman) at 10:43:14.
Type `help' to learn how to use Xshell prompt.
已经顺利压缩完成,主目录的文件名 huoniao-2017-03-26.7z[root@VM_18_10_centos /]# ll
total 9471004
dr-xr-xr-x. 2 root root 4096 Mar 3 12:37 bin
dr-xr-xr-x. 4 root root 4096 Mar 3 09:15 boot
drwxr-xr-x 2 root root 4096 Nov 9 11:57 data
drwxr-xr-x 16 root root 3380 Mar 3 16:34 dev
drwxr-xr-x. 73 root root 4096 Mar 3 16:34 etc
drwxrwxrwx 2 root root 4096 Mar 3 15:12 hnbak
drwxr-xr-x. 2 root root 4096 Sep 23 2011 home
drwxrwxrwx 3 root root 4096 Mar 26 10:53 huoniao
-rw-r--r-- 1 root root 9688588793 Mar 26 02:51 huoniao-2017-03-26.7z
dr-xr-xr-x. 11 root root 4096 Mar 3 12:18 lib
dr-xr-xr-x. 9 root root 12288 Mar 3 12:19 lib64
drwx------. 2 root root 16384 Nov 9 11:45 lost+found
drwxr-xr-x. 2 root root 4096 Sep 23 2011 media
drwxr-xr-x. 2 root root 4096 Sep 23 2011 mnt
drwxr-xr-x. 3 root root 4096 Nov 9 11:48 opt
dr-xr-xr-x 132 root root 0 Mar 3 16:33 proc
dr-xr-x---. 3 root root 4096 Mar 3 09:20 root
dr-xr-xr-x. 2 root root 12288 Nov 9 11:48 sbin
drwxr-xr-x. 2 root root 4096 Nov 9 11:45 selinux
drwxr-xr-x. 2 root root 4096 Sep 23 2011 srv
drwxr-xr-x 13 root root 0 Mar 3 16:33 sys
drwxrwxrwt. 3 root root 118784 Mar 26 10:53 tmp
drwxr-xr-x. 14 root root 4096 Mar 3 12:42 usr
drwxr-xr-x. 19 root root 4096 Nov 9 11:48 var
drwxr-xr-x 5 root root 4096 Mar 3 12:38 www
[root@VM_18_10_centos /]#
7z命令排除文件夹的例子: 排除uploads、phpmailer两个文件夹
7z a -t7z /huoniao/20171003.7z /huoniao/web/aus168_com/public_html/ -mhcf -mmt -r -xr\!uploads -xr\!phpmailer
7z a -t7z /1.zip /www/ihuoniao.cn/ -mhcf -mmt -r -xr\!uploads -xr\!templates -xr0\!*.sql -xr\!backup
[root@iZp0w0bp7w7vul720hq98lZ public_html]# 7z a -t7z /huoniao/20171003.7z /huoniao/web/aus168_com/public_html/ -mhcf -mmt -r -xr\!uploads -xr\!phpmailer
7-Zip [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,2 CPUs Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz (406F1),ASM,AES-NI)
Scanning the drive:
1880 folders, 20289 files, 387211806 bytes (370 MiB)
Creating archive: /huoniao/20171003.7z
Items to compress: 22169
Files read from disk: 20240
Archive size: 198601206 bytes (190 MiB)
Everything is Ok
[root@iZp0w0bp7w7vul720hq98lZ public_html]#
[root@iZp0w0bp7w7vul720hq98lZ huoniao]# du -sh *
190M20171003.7z
159Mdb_web_data
6.5Gweb
11Gweb_2017-09-30
[root@iZp0w0bp7w7vul720hq98lZ huoniao]#
-v指定分卷大小
{Size}[b | k | m | g]
指定分卷大小,可以使用字节、KB(1 KB=1024 字节),MB(1 MB = 1024 KB)或 GB(1 GB = 1024 MB)。
如果您只指定了 {Size},7-zip 将把它视为字。
7z a a.7z *.txt -v10k -v15k -v2m : 创建 a.7z 分卷压缩档案。第一个分卷为 10 KB,第二个为 15 KB,剩下全部为 2 MB。
大于10G以上文件夹,分3G卷打包
7z a -t7z /kuman/www/huoniao_20190512.7z /kuman/www/wwwroot/26dj.com/ -mhcf -mmt -r -v3g[root@ecs-eedb ~]# 7z a -t7z /kuman/www/huoniao_20190512.7z /kuman/www/wwwroot/26dj.com/ -mhcf -mmt -r -v3g
7-Zip [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,8 CPUs Intel(R) Xeon(R) Gold 6278C CPU @ 2.60GHz (50657),ASM,AES-NI)
Scanning the drive:
11142 folders, 149375 files, 16325307459 bytes (16 GiB)
Creating archive: /kuman/www/huoniao_20190512.7z
Items to compress: 160517
Files read from disk: 148452
Archive size: 14621014941 bytes (14 GiB)
Everything is Ok
[root@ecs-eedb ~]#
教程结束 ~