linux解压7z文件,linux 中解压7z文件

本文详细介绍了在Linux环境下如何使用7z命令进行文件的解压和压缩,包括安装7z软件包,查看7z命令的使用说明,以及提供多个具体的解压和压缩示例,涵盖了不同参数的使用方法,如设置输出目录、覆盖现有文件等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 ~]#

教程结束 ~

<think>好的,用户的问题是在Linux系统中如何使用命令行解压.7z文件。我需要根据提供的引用内容来整理答案。首先,我需要确认用户的操作系统是Linux,所以引用中提到的Ubuntu和其他发行版都是相关的。 引用1提到如果无法提取.7z文件,需要安装7zip。因此,首先应该指导用户安装p7zip软件包。安装命令应该是sudo apt install p7zip-full,适用于基于Debian的系统。然后,解压的基本命令是7z x 文件名.7z,其中x表示解压。 引用3也提到了类似的命令,7z e可以释放文件,但这里e和x的区别可能需要解释。通常,x会保留目录结构,而e则是解压所有文件到当前目录,可能忽略路径。所以应该建议用户使用x选项更合适。 另外,用户可能想知道如何指定解压路径,这时候需要提到使用-o选项,比如7z x file.7z -o/path/to/extract,这里要注意-o后面没有空格,直接跟路径。 引用2和4提到了.tar.gz文件解压方法,但用户的问题是关于.7z的,所以这部分可能不需要,不过如果有用户同时处理多层压缩,比如先解压.tar.gz得到.tar,再解压.tar,但这里用户的问题明确是.7z,所以重点放在7z命令上。 需要检查是否有其他相关选项,比如列出压缩包内容用7z l,测试完整性用7z t,这些可以作为附加信息帮助用户更多操作。 最后,确保步骤清晰:安装软件包,使用解压命令,可选参数说明,以及常见问题比如路径不存在如何处理。同时,注意命令的正确性,比如选项的正确拼写和顺序。</think>在 Linux 系统中解压 `.7z` 文件需要安装 `p7zip` 工具,以下是详细步骤: ### 1. 安装 p7zip 通过终端执行以下命令安装(适用于 Debian/Ubuntu 等基于 APT 的系统): ```bash sudo apt update && sudo apt install p7zip-full ``` ### 2. 解压 .7z 文件 使用以下命令解压文件到当前目录: ```bash 7z x 文件名.7z ``` - `x` 表示完整路径解压,保留压缩包内目录结构 - 若需指定解压路径,添加 `-o` 参数(注意无空格): ```bash 7z x 文件名.7z -o目标路径 # 示例:7z x data.7z -o/home/user/documents ``` ### 3. 其他常用命令 | 功能 | 命令 | |------|------| | 列出压缩包内容 | `7z l 文件名.7z` | | 测试压缩包完整性 | `7z t 文件名.7z` | | 仅解压特定文件 | `7z x 文件名.7z 目标文件路径` | ### 注意事项 - 若解压路径不存在,需提前创建目录 - 使用 `7z e 文件名.7z` 可忽略压缩包内目录结构,直接将所有文件释放到当前目录[^3]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值