Linux工具|运维工具7za浅谈

2023-11-21 02:14:04 浏览数 (1)

1、背景

前几日,需要从线上环境拉取部分数据导入到实验库,将工作告知运维后,运维发给我一些文件,文件内容如下格式:

xxx7z.001

xxx7z.002

xxx7z.003

xxx7z.004

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

2、7zip简介

7-zip以高压缩率著称,并且是一款免费开源的压缩软件。在常规的Linux发行版中,无法通过简单的yum命令来安装该软件。那么在CentOS中,如何安装7ZIP呢?

3、7-zip安装

第一种,源码编译安装

官网下载地址:http://www.7-zip.org/download.html

源文件项目地址:http://sourceforge.net/projects/p7zip/,目前最新版为9.20.1。

执行以下命令下载安装:

代码语言: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

第二种,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

第三种,yum安装

通过《在Centos 5.x或6.x上安装RHEL EPEL Repo》一文,安装RHEL EPEL Repo后,即可使用yum安装7ZIP。

命令如下:

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

4、使用方法

使用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.jpgl 列出压缩包里的文件,如列出001.7z里的文件,执行:7za l 001.7ze 解压到当前目录,目录结构会被破坏,如001.rar内有如下目录及文件123/456/789.html,执行:7za e 001.rar,目录123和456及文件789.html都会存放在当前目录下。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复制
$ 7za --help

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,12 CPUs x64)

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

现在,学会了吗?

有些时候,互联网免费工具,且用且珍惜❤️。


我正在参与2023腾讯技术创作特训营第三期有奖征文,组队打卡瓜分大奖!

0 人点赞