链接:http://www.2cto.com/os/201410/341079.html
7z指令
7z是7zip压缩工具的常用压缩文件格式。7zip是一个开源的压缩工具,软件本身十分小巧,功能强大,是目前公认的压缩比最大的压缩解压缩软件,近年来开始渐渐流行。

7zip支持众多的压缩格式,支持7z, XZ,BZIP2, GZIP, TAR, ZIP格式的压缩/解压缩。支持CAB, ISO, RAR, RPM, XAR, Z等众多格式的解压缩。

程序退出代码0表示正常,没有错误。

命令格式
$ 7z –help

Usage: 7z […] […]

[<@listfiles…>]

常用的command如下:

a 添加文件到压缩文件

d 从压缩文件中删除文件

e 从压缩文件中解压缩文件,不包含目录结构

l 列出压缩包中的内容

t 测试压缩文件

u更新文件到压缩文件

x从压缩文件中解压缩,包含目录结构

使用示例
$ rm * -rf

$ mkdir -p study/d1/d11 study/d2

$ touch study/d1/d11/f1.c study/d2/f2.php

$ 7z a study.7z study/ ~ 将study整个目录添加到压缩包study.7z中

Scanning

Creating archive study.7z

Everything is Ok

$ 7z t study.7z ~ 测试压缩包

Processing archive: study.7z

Testing study/d1/d11/f1.c

Testing study/d2/f2.php

Testing study/d2

Testing study/d1/d11

Testing study/d1

Testing study

Everything is Ok

$ rm -rf study

$ 7z x study.7z ~ 解压缩包到当前目录

Processing archive: study.7z

Extracting study/d1/d11/f1.c

Extracting study/d2/f2.php

Extracting study/d2

Extracting study/d1/d11

Extracting study/d1

Extracting study

Everything is Ok

$ 7z d study.7z study/d2/f2.php ~ 删除压缩包中的指定文件

Updating archive study.7z

Everything is Ok

$ 7z t study.7z ~ 测试压缩包

Processing archive: study.7z

Testing study/d1/d11/f1.c

Testing study/d2

Testing study/d1/d11

Testing study/d1

Testing study

Everything is Ok

$ 7z l study.7z ~ 查看压缩包中的目录结构

Listing archive: study.7z

Path = study.7z

Type = 7z

Solid = -

Blocks = 0

Physical Size = 152

Headers Size = 152

study/d1/d11/f1.c

study/d2

study/d1/d11

study/d1

study

$ 7z u study.7z study/d1/d11/f1.c ~ 更新压缩包中的指定文件

Scanning

Updating archive study.7z

Compressing study/d1/d11/f1.c

Everything is Ok

$ 7z l study.7z ~ 查看压缩包中的目录结构

Listing archive: study.7z

Path = study.7z

Type = 7z

Method = LZMA

Solid = -

Blocks = 1

Physical Size = 260

Headers Size = 186

study/d1/d11/f1.c

study/d2

study/d1/d11

study/d1

study

7zip的压缩格式控制
在上述示例中,演示了7z压缩/解压缩指令的使用。在使用7z进行压缩/解压缩时,压缩格式是根据命令中提供的压缩包的文件后缀名来识别的。例如,7z a study.zip study/ 将目录树study按照zip格式进行压缩,7z a study.7z study/将目录树study按照7z格式进行压缩。反之,解压缩时,压缩格式也是根据压缩包文件名后缀自动识别的。

对于7zip和tar的各种压缩格式(tar.gz tar.bz2 tar.xz)之间的兼容,可以参考如下实现。

$ 7z a study4.tar study ~ step1 先按tar格式进行打包

按照实验结果推断,本条指令与tar cf study4.tar study 具有相同效果

Scanning

Creating archive study4.tar

Compressing study

Compressing study/d1

Compressing study/d1/d11

Compressing study/d1/d11/f1.c

Compressing study/d2

Compressing study/d2/f2.php

Everything is Ok

$ 7z a study4.tar.gz study4.tar ~ 将已打包的文件进行按gzip格式压缩

Scanning

Creating archive study4.tar.gz

Compressing study4.tar

Everything is Ok

$tar tf study4.tar ~ 使用tar指令测试文件包,无错误

study/

study/d1/

study/d1/d11/

study/d1/d11/f1.c

study/d2/

study/d2/f2.php

$tar tf study4.tar.gz ~ 使用tar指令测试压缩包,无错误

study/

study/d1/

study/d1/d11/

study/d1/d11/f1.c

study/d2/

study/d2/f2.php

$ rm study -rf

$tar xzvf study4.tar.gz ~ 使用tar解压缩由7z生成的.tar.gz压缩包,成功。

study/

study/d1/

study/d1/d11/

study/d1/d11/f1.c

study/d2/

study/d2/f2.php

$ rm .

$ ls

study

$tar czf study4.tar.gz study ~ 使用tar指令生成.tar.gz格式压缩包

$ 7z x study4.tar.gz ~ 使用7z解压缩tar生成的压缩包,成功

Processing archive: study4.tar.gz

Extracting study4.tar

Everything is Ok

$ 7z x study4.tar ~ 使用7z进一步解压,成功

Processing archive: study4.tar

Extracting study

Extracting study/d1

Extracting study/d1/d11

Extracting study/d1/d11/f1.c

Extracting study/d2

Extracting study/d2/f2.php

Everything is Ok

$

$tar cvf study5.tar study ~ 使用tar创建无压缩的文件包

study/

study/d1/

study/d1/d11/

study/d1/d11/f1.c

study/d2/

study/d2/f2.php

$ 7z a study5.tar.bz2 study5.tar ~ 使用7zip将文件包压缩

Scanning

Creating archive study5.tar.bz2

Compressing study5.tar

Everything is Ok

$tar tf study5.tar.bz2 ~ 使用tar测试压缩包

study/

study/d1/

study/d1/d11/

study/d1/d11/f1.c

study/d2/

study/d2/f2.php

$ 7z x study5.tar.bz2 ~ 使用7zip解压缩压缩包

Processing archive: study5.tar.bz2

file study5.tar

Extracting study5.tar

Everything is Ok

$ rm -rf study

$ 7zx study5.tar ~ 使用7zip还原tar指令生成的文件包

Processing archive: study5.tar

Extracting study

Extracting study/d1

Extracting study/d1/d11

Extracting study/d1/d11/f1.c

Extracting study/d2

Extracting study/d2/f2.php

Everything is Ok

$ rm study -rf

$tar xjvf study5.tar.bz2 ~ 使用tar解压缩tar+7zip生成的.tar.bz2压缩包

study/

study/d1/

study/d1/d11/

study/d1/d11/f1.c

study/d2/

study/d2/f2.php

$

---------------------

本文来自 Setoge 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/Setoge/article/details/79760065?utm_source=copy

05-11 14:47