Centos7中安装并使用7-Zip具体方法

7-Zip(7z解压软件)是一款完全免费的压缩解压缩软件,同其他压缩软件相比它的压缩速度更快压缩率更好,不仅支持众多主流格式、支持超线程,而且还有强大的AES-256加密算法可以为文件进行加密,增强文件的安全性,下面为大家详细讲解一下Centos7中安装并使用7-Zip具体方法。

环境

  • Centos7.7 Minimal
  • p7zip-16.02

安装

默认Centos7没有安装p7zip安装包,默认源里面也没有这个安装包,需要安装epel源才能安装p7zip安装包。

[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install p7zip p7zip-plugins

使用方法

7z命令提供的函数字母与命令行选项类似,但使用时不使用-。这些参数字母告诉命令它需要执行的函数。

压缩文件

创建一个压缩包使用a参数

创建一个7z格式的压缩包:

[root@localhost ~]# 7z a files.7z file1.txt file2.txt file3.txt file4.txt

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,1 CPU Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (906EA),ASM,AES-NI)

Scanning the drive:
4 files, 0 bytes

Creating archive: files.7z

Items to compress: 4

   
Files read from disk: 0
Archive size: 143 bytes (1 KiB)
Everything is Ok

执行完命令,查看一下是否已经创建7z格式的压缩包 创建一个包含目录的压缩包:

[root@localhost ~]# 7z a gpg.7z .gnupg/

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,1 CPU Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (906EA),ASM,AES-NI)

Scanning the drive:
2 folders, 5 files, 8280 bytes (9 KiB)

Creating archive: gpg.7z

Items to compress: 7

   
Files read from disk: 2
Archive size: 4157 bytes (5 KiB)
Everything is Ok
[root@localhost ~]#

7zip还可以压缩、解压缩其他格式的压缩包。比如:创建一个.zip格式的压缩包。

[root@localhost ~]# 7z a files.zip file{1..4}.txt

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,1 CPU Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (906EA),ASM,AES-NI)

Scanning the drive:
4 files, 0 bytes

Creating archive: files.zip

Items to compress: 4

   
Files read from disk: 4
Archive size: 542 bytes (1 KiB)
Everything is Ok

Centos7中使用7zip压缩工具Centos7中使用7zip压缩工具

列出压缩包里面的内容

列出压缩包的内容使用l参数:

[root@localhost ~]# 7z l gpg.7z

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,1 CPU Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (906EA),ASM,AES-NI)

Scanning the drive for archives:
1 file, 4157 bytes (5 KiB)

Listing archive: gpg.7z

--
Path = gpg.7z
Type = 7z
Physical Size = 4157
Headers Size = 278
Method = LZMA2:12k
Solid = +
Blocks = 1

  Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2020-01-04 18:24:05 D....            0            0  .gnupg
2020-01-04 18:22:36 D....            0            0  .gnupg/private-keys-v1.d
2020-01-04 18:24:48 ....A            0            0  .gnupg/S.gpg-agent
2020-01-04 18:22:36 ....A            0            0  .gnupg/pubring.gpg
2020-01-04 18:24:05 ....A            0            0  .gnupg/secring.gpg
2020-01-04 18:22:36 ....A         7680         3879  .gnupg/gpg.conf
2020-01-04 18:24:52 ....A          600               .gnupg/random_seed
------------------- ----- ------------ ------------  ------------------------
2020-01-04 18:24:52               8280         3879  5 files, 2 folders

Centos7中使用7zip压缩工具Centos7中使用7zip压缩工具

解压文件

使用e来解压文件,解压所有文件到当前目录。(不推荐使用)

[root@localhost test]# 7z e gpg.7z

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,1 CPU Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (906EA),ASM,AES-NI)

Scanning the drive for archives:
1 file, 4157 bytes (5 KiB)

Extracting archive: gpg.7z
--
Path = gpg.7z
Type = 7z
Physical Size = 4157
Headers Size = 278
Method = LZMA2:12k
Solid = +
Blocks = 1

Everything is Ok

Folders: 2
Files: 5
Size:       8280
Compressed: 4157

可以看到所有文件都解压到当前目录了。 现在使用x参数解压文件看一下。

[root@localhost test]# 7z x gpg.7z

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,1 CPU Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (906EA),ASM,AES-NI)

Scanning the drive for archives:
1 file, 4157 bytes (5 KiB)

Extracting archive: gpg.7z
--
Path = gpg.7z
Type = 7z
Physical Size = 4157
Headers Size = 278
Method = LZMA2:12k
Solid = +
Blocks = 1

Everything is Ok

Folders: 2
Files: 5
Size:       8280
Compressed: 4157

可以看到解压出来的文件,按照原来文件的目录形式解压出来的。

更新压缩包

一段时间之后,需要将一些新文件添加到文件夹中,并且希望将他们添加到压缩包里面,可以不用创建一个新的压缩包,只需要更新现有的压缩包就可以。

首先将test目录压缩

[root@localhost test]# 7z a files.7z test/

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,1 CPU Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (906EA),ASM,AES-NI)

Scanning the drive:
1 folder, 4 files, 0 bytes

Creating archive: files.7z

Items to compress: 5

   
Files read from disk: 0
Archive size: 158 bytes (1 KiB)
Everything is Ok

在test文件夹中创建几个文件,然后再更新压缩包:

[root@localhost test]# touch test/file{5..10}.txt
[root@localhost test]# 7z u files.7z test/

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,1 CPU Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (906EA),ASM,AES-NI)

Open archive: files.7z
--
Path = files.7z
Type = 7z
Physical Size = 158
Headers Size = 158
Solid = -
Blocks = 0

Scanning the drive:
1 folder, 10 files, 0 bytes

Updating archive: files.7z

Items to compress: 7

   
Files read from disk: 0
Archive size: 186 bytes (1 KiB)
Everything is Ok

查看一下是否已经添加文件。

[root@localhost test]# 7z l files.7z

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,1 CPU Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (906EA),ASM,AES-NI)

Scanning the drive for archives:
1 file, 186 bytes (1 KiB)

Listing archive: files.7z

--
Path = files.7z
Type = 7z
Physical Size = 186
Headers Size = 186
Solid = -
Blocks = 0

  Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2020-03-11 14:24:54 D....            0            0  test
2020-03-11 14:18:22 ....A            0            0  test/file1.txt
2020-03-11 14:24:54 ....A            0            0  test/file10.txt
2020-03-11 14:18:22 ....A            0            0  test/file2.txt
2020-03-11 14:18:22 ....A            0            0  test/file3.txt
2020-03-11 14:18:22 ....A            0            0  test/file4.txt
2020-03-11 14:24:54 ....A            0            0  test/file5.txt
2020-03-11 14:24:54 ....A            0            0  test/file6.txt
2020-03-11 14:24:54 ....A            0            0  test/file7.txt
2020-03-11 14:24:54 ....A            0            0  test/file8.txt
2020-03-11 14:24:54 ....A            0            0  test/file9.txt
------------------- ----- ------------ ------------  ------------------------
2020-03-11 14:24:54                  0            0  10 files, 1 folders

Centos7中使用7zip压缩工具Centos7中使用7zip压缩工具

总结

7z格式的压缩比例比ZIP格式的压缩比例高30%-50%。

原创文章,作者:晴川运维,如若转载,请注明出处:https://baike.qcidc.com/9647.html

(0)
晴川运维晴川运维
上一篇 2025年6月18日
下一篇 2025年6月18日

相关推荐

  • Centos7中安装轻量级运维利器:pssh

    pssh 提供了并行版本的 OpenSSH 工具,特别适合用来控制有大量机器需要连接的情况,包括并行版本的 ssh、scp、rsync 和 kill 命令。 下载pssh安装包 […

    CentOS 2025年6月23日
  • Linux系统之TroubleShooting(CentOS启动故障排除)

    尽管linux系统非常强大,稳定,但是我们在使用过程当中,如果人为操作不当,仍然会影响系统,甚至可能使得系统无法开机,无法运行服务等等各种问题。那么这篇博文就总结一下一些常见的故障…

    CentOS 2025年6月8日
  • CentOS 7从Python 2.7升级至Python3.6.1

    引言: centos是目前最为流行的linux服务器系统,其默认的python 2.x,但是根据python社区的规划,在不久之后,整个社区将向Python3迁移,且将不在支持Py…

    CentOS 2025年7月2日
  • CentOS6.5下RPM方式安装MySQL5.6.33

    centos6.5下RPM方式安装mysql5.6.33 1、mysql下载 下载地址:https://dev.mysql.com/downloads/mysql/5.6.html…

    CentOS 2025年6月13日
  • 磁盘管理之软RAID

    1、RAID概述   RAID,Redundant Arrays of Inexpensive(Independent)Disks的简称,独立磁盘冗余阵列,简称磁盘阵列。…

    CentOS 2025年6月8日
  • CentOS7.3环境下源码安装httpd2.4

    本文在centos7.3下,源码安装apache服务httpd2.4。 1.下载好源码安装包   [root@localhost ~]#ll   total 6252   -rw-…

    CentOS 2025年7月7日
  • Linux中配置Nginx Web服务器过程

    linux系统环境:CentOS 7 需要软件:nginx-1.3.16.tar.gz  libevent-2.0.21-stable.tar.gz  Pcre…

    CentOS 2025年6月21日
  • CentOS 7实现PXE支持CentOS5,6,7的系统安装

    本博主要目的为实现自定义页面自动化安装系统,基于PXE支持的网卡,目前实现环境为VMware虚拟机。所用镜像为CentOS6.9,CentOS7.3及rhel5.4。支持中小规模自…

    CentOS 2025年6月8日
  • CentOS下使用EPEL源具体方法

    EPEL (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额外的软件包,适用于RHEL、CentO…

    CentOS 2025年6月12日
  • Centos flock 防止脚本重复运行

    如果crontab设定任务每分钟执行一次,但执行的任务需要花费5分钟,这时系统会再执行导致两个相同的任务在执行。发生这种情况下可能会出现一些并发问题,严重时会导致出现脏数据性能瓶颈…

    CentOS 2025年7月3日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注