>>Technical application: CentOS (Linux) decompression tool 7za

background

A few days ago, I needed to pull some data from the online environment and import it into the experimental library. After notifying the operation and maintenance of the work, the operation and maintenance sent me a

xxx7z.001
xxx7z.002
xxx7z.003
xxx7z.004

When I saw this at first glance, I didn't know how to deal with it. Finally, the operation and maintenance informed me that I need to use the 7za tool to deal with it. In order to consolidate what I have learned, let's start to study this software tool.

Introduction to 7-zip

7-zip is known for its high compression rate and is a free and open source compression software. In regular Linux distributions, the software cannot be installed through a simple yum command. So in CentOS, how to install 7ZIP (other environments or gadgets can be downloaded from Baidu)?

7-zip install

M1 Linux source code compilation and installation

Official website download address: http://www.7-zip.org/download.html The latest version is 22.01.

The installation is relatively simple, execute the following commands in order to download and install:

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

When the following message appears after the last step make install, the installation is complete.

./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) installation

Download address: http://pkgs.repoforge.org/p7zip/ , please refer to the latest version.

Install 7ZIP under CentOS 5.x 32-bit

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

Install 7ZIP under CentOS 5.x 64-bit

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

Install 7ZIP under CentOS 6.x 32-bit

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

Install 7ZIP under CentOS 6.x 64-bit

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) installation

During the installation through M2 above, after installing RHEL EPEL Repo, you can use yum to install 7ZIP.
The command is as follows:

yum install -y p7zip

M4 MacOS (brew) installation

It is more convenient to install in macOS, and you can use brewtools to find, install, use, and uninstall.

  • 【Search】
$ brew search 7zip
==> Formulae
7-zip             7zip             p7zip               zip

Of course, you 7zcan also search

$ brew search 7z
==> Formulae
7-zip               7zip                  p7zip
  • 【Install】
$ 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

The installation process is relatively simple, and it can be used after installation.

Install in M5 Windows (exe)

It is relatively simple in windows, just put a download link: https://7-zip.org/download.html

Note ⚠️: Different software is installed, and the commands may be different, for example 7za, , 7zzetc.

Instructions

The command to use 7zip is 7za. How to use after installation:

  • "How to use"

7za {a|d|l|e|u|x} compressed package file name {file list or directory, optional}

in,

  • a : Add files to the compressed package or create a compressed package.
    • For example, add 001.jpg to 001.7z, execute: 7za a 001.7z 001.jpg; package the 001 directory and execute: 7za a 001.7z 001;
  • d : Delete files from compression, such as deleting 001.jpg in 001.7z, execute: 7za d 001.7z 001.jpg
  • l : List the files in the archive.
    • To list the files in 001.7z, execute: 7za l 001.7z
  • e : Extract to the current directory (does not contain the directory structure).
    • The directory structure will be destroyed. For example, there are the following directories and files 123/456/789.html in 001.rar,
      execute: 7za e 001.rar, directories 123 and 456 and file 789.html will be stored in the current directory.
  • u : Update files to compressed files.
  • x : Extract with full path (including directory structure).
    • Chinese files are garbled when decompressing a zip file. Since the encoding is not declared in the zip file, if you use unzip to decompress with the default encoding on Linux, the Chinese file name will be garbled.

help command

When you really don't know how to use it, try to go to Baidu, where there are answers you need. But when there is no network, you can use the help command to achieve it, for example

Use the help command in CentOS

$ 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

Use the help command in MacOS

$ 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

write at the end

Sometimes, there are some orders, you still have to look at them, forget them quickly, take notes, so that you don't look like a rabbit fishing for fish.

Guess you like

Origin blog.csdn.net/L_Lycos/article/details/129394561