前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >>>技术应用:CentOS(Linux)的解压工具7za

>>技术应用:CentOS(Linux)的解压工具7za

作者头像
艾特
发布2023-10-10 14:56:02
4490
发布2023-10-10 14:56:02

背景

前几日,需要从线上环境拉取部分数据导入到实验库,将工作告知运维后,运维发给我一个

代码语言:javascript
复制
xxx7z.001
xxx7z.002
xxx7z.003
xxx7z.004

看到这个第一眼,不知道怎么处理了,最后运维告知需要使用7za工具处理。为了巩固自己所学,下面开始研究下这个软件工具。

7-zip简介

7-zip以高压缩率著称,并且是一款免费开源的压缩软件。在常规的Linux发行版中,无法通过简单的yum命令来安装该软件。那么在CentOS中,如何安装7ZIP呢(其他环境或者小工具可以百度下哈)?

7-zip安装

M1 Linux源码编译安装

官网下载地址:http://www.7-zip.org/download.html 最新的版本为22.01。

安装比较简单,依次执行以下命令下载安装:

代码语言:javascript
复制
wget http://nchc.dl.sourceforge.net/project/p7zip/p7zip/9.20.1/p7zip_9.20.1_src_all.tar.bz2

tar -jxvf p7zip_9.20.1_src_all.tar.bz2

cd p7zip_9.20.1

make

make install

最后一步make install后出现以下信息,即为安装完毕。

代码语言:javascript
复制
./install.sh /usr/local/bin /usr/local/lib/p7zip /usr/local/man /usr/local/share/doc/p7zip

● installing /usr/local/bin/7za
● installing /usr/local/man/man1/7z.1
● installing /usr/local/man/man1/7za.1
● installing /usr/local/man/man1/7zr.1
● installing /usr/local/share/doc/p7zip/README
● installing /usr/local/share/doc/p7zip/ChangeLog
● installing HTML help in /usr/local/share/doc/p7zip/DOCS

M2 Linux(rpm)安装

下载地址:http://pkgs.repoforge.org/p7zip/,请以最新版为准。

在 CentOS 5.x 32位下安装7ZIP

代码语言:javascript
复制
wget http://pkgs.repoforge.org/p7zip/p7zip-9.20.1-1.el5.rf.i386.rpm
rpm -ivh p7zip-9.20.1-1.el5.rf.i386.rpm

在 CentOS 5.x 64位下安装7ZIP

代码语言:javascript
复制
wget http://pkgs.repoforge.org/p7zip/p7zip-9.20.1-1.el5.rf.x86_64.rpm
rpm -ivh p7zip-9.20.1-1.el5.rf.x86_64.rpm

在 CentOS 6.x 32位下安装7ZIP

代码语言:javascript
复制
wget http://pkgs.repoforge.org/p7zip/p7zip-9.20.1-1.el6.rf.i686.rpm
rpm -ivh p7zip-9.20.1-1.el6.rf.i686.rpm

在 CentOS 6.x 64位下安装7ZIP

代码语言:javascript
复制
wget http://pkgs.repoforge.org/p7zip/p7zip-9.20.1-1.el6.rf.x86_64.rpm
rpm -ivh p7zip-9.20.1-1.el6.rf.x86_64.rpm

M3 Linux(yum)安装

通过上面M2执行安装中,安装RHEL EPEL Repo后,即可使用yum安装7ZIP。 命令如下:

代码语言:javascript
复制
yum install -y p7zip

M4 MacOS(brew)安装

在macOS中安装就比较方便了,可以使用brew工具来查找、安装、使用和卸载等操作。

  • 【查找】
代码语言:javascript
复制
$ brew search 7zip
==> Formulae
7-zip             7zip             p7zip               zip

当然,搜索7z也是可以的

代码语言:javascript
复制
$ brew search 7z
==> Formulae
7-zip               7zip                  p7zip
  • 【安装】
代码语言:javascript
复制
$ brew install 7zip
==> Downloading https://downloads.sourceforge.net/project/p7zip/p7zip/9.20.1/p7zip_9.20.1_src_all.tar.bz2

######################################################################## 100.0%

==> make all3 CC=clang $(ALLFLAGS) CXX=clang++ $(ALLFLAGS)

==> make DEST_HOME=/usr/local/Cellar/p7zip/9.20.1 DEST_MAN=/usr/local/Cellar/p7zip/9.20.1/share/man install

==> chmod -R +w /usr/local/Cellar/p7zip/9.20.1/share/doc/p7zip

安装过程比较简单,安装后可以使用了。

M5 Windows(exe)中安装

在windows中就比较简单了,放一个下载连接即可:https://7-zip.org/download.html

注意⚠️:安装了不同的软件,使用命令可能不一样,例如7za7zz等。

使用方法

使用7zip的命令是7za。安装完成后的使用方法:

  • 「使用方法说明」

7za {a|d|l|e|u|x} 压缩包文件名 {文件列表或目录,可选}

其中,

  • a :向压缩包里添加文件或创建压缩包。
    • 如向001.7z添加001.jpg,执行:7za a 001.7z 001.jpg;将001目录打包执行:7za a 001.7z 001;
  • d :从压缩里删除文件,如将001.7z里的001.jpg删除,执行:7za d 001.7z 001.jpg
  • l :列出压缩包里的文件。
    • 如列出001.7z里的文件,执行:7za l 001.7z
  • e :解压到当前目录(不包含目录结构)。
    • 目录结构会被破坏,如001.rar内有如下目录及文件123/456/789.html, 执行:7za e 001.rar,目录123和456及文件789.html都会存放在当前目录下。
  • u :更新文件到压缩文件。
  • x :以完整路径解压(包含目录结构)。
    • zip文件解压中文文件乱码问题,由于zip文件中没有声明其编码,所以在Linux上使用unzip解压以默认编码解压,中文文件名会出现乱码。

帮助命令

当实在是不会使用的时候,尽量去百度,那里有你需要的答案。但是在没有网络的时候,就可以使用帮助命令来实现,例如

CentOS中使用帮助命令

代码语言:javascript
复制
$ 7za --help
7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=zh_CN.UTF-8,Utf16=on,HugeFiles=on,64 bits,4 CPUs Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz (406F1),ASM,AES-NI)

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[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

MacOS中使用帮助命令

代码语言:javascript
复制
$ 7zz --help

7-Zip (z) 21.07 (x64) : Copyright (c) 1999-2021 Igor Pavlov : 2021-12-26
 64-bit locale=zh_CN.UTF-8 Threads:12

Usage: 7zz <command> [<switches>...] <archive_name> [<file_names>...] [@listfile]

<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 and @listfile 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
    -mx[N] : set compression level: -mx1 (fastest) ... -mx9 (ultra)
  -o{Directory} : set Output directory
  -p{Password} : set Password
  -r[-|0] : Recurse subdirectories for name search
  -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
  -sse : stop archive creating, if it can't open some input file
  -ssp : do not change Last Access Time of source files while archiving
  -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

写在最后

有些时候,有些命令,还是得看看,忘记的挺快,做笔记吧,让自己看上去不那么像一只摸鱼的兔子。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-10-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 背景
  • 7-zip简介
  • 7-zip安装
    • M1 Linux源码编译安装
      • M2 Linux(rpm)安装
        • M3 Linux(yum)安装
          • M4 MacOS(brew)安装
            • M5 Windows(exe)中安装
            • 使用方法
            • 帮助命令
              • CentOS中使用帮助命令
                • MacOS中使用帮助命令
                • 写在最后
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档