7z

Open source compression software with extremely high compression ratio.

Install

Enter the following command to install 7-Zip in Linux.

# Ubuntu system
apt-get update
apt-get install p7zip-full -y

# CentOS reference: https://linuxconfig.org/how-to-install-p7zip-on-redhat-8
sudo yum install epel-release
yum install p7zip p7zip-plugins

Example

Introducing several common scenarios: decompression, compression, and viewing (compressed package contents).

7z x text.7z
# Note -o is used to specify the directory where the decompressed file is stored. There is no space after -o. Directly connect to the directory.
7z x text.7z -r -o/home/text
# Note that dir1/dir2, dir1/file1 is the file or folder path in the compressed package
7z x text.7z dir1/dir2 dir1/file1 -o/home/text
7z a text.7z -r /home/text
7z l text.7z

help message translation

Usage: 7z <command> [<switch>...] <archive_name> [<file_names>...]

<command>
   a: Add files to the compressed package
   b : Benchmark test
   d: delete files from compressed package
   e: Extract files from the compressed archive (without using directory names).
   h : Calculate the hash value of the file
   i: Display supported format information
   l: List the contents of the compressed package
   rn: Rename files in the compressed package
   t: Test the integrity of the compressed package
   u: Update files in the compressed package
   x : Extract the file with full path

<switch>
   -- : Stop parsing switches starting with - and file lists starting with @, in order to allow 7-Zip to use file names starting with - and @.
   -ai[r[-|0]]{@listfile|!wildcard}: Include the specified compressed package file
   -ax[r[-|0]]{@listfile|!wildcard} : Exclude the specified compressed package file
   -ao{a|s|t|u} : Set overwrite mode
     -aoa Overwrites all existing files silently.
     -aos Skip extracting existing files.
     -aou Automatically rename extracted files (for example, name.txt will be renamed to name_1.txt).
     -aot Automatically rename existing files (for example, name.txt will be renamed to name_1.txt).
   -an: Disable archive name field parsing, must be used with the -ai switch.
   -bb[0-3]: Set output log level
     -bb0 disables logging (default).
     -bb1 or -bb Display the names of processed files in the log.
     -bb2 Display skipped file names (for "Extract" operation) and repacked file names (for "Add" / "Update" operations) in the archive file
     -bb3 Display other operation (analyze, copy) information for "Add" / "Update" operations.
   -bd : disable progress indicator
   -bs{o|e|p}{0|1|2} : Set the output stream for output/error/progress lines
     o Standard output information
     e error message
     p progress information
     0 disables streaming
     1 Redirect to standard output stream
     2 Redirect to standard error stream
   -bt: Display execution time statistics
   -i[r[-|0]]{@listfile|!wildcard} : include file name
   -m{Parameters}: Set compression method
     -mmt[N]: Set the number of CPU threads
     -mx[N]: Set the compression level: -mx1 (fastest) ... -mx9 (super strong), -mx0 (no compression)
   -o{Directory}: Set the output directory
   -p{Password}: set password
   -r[-|0] : re-search subdirectories
   -sa{a|e|s}: Set the compressed package name pattern
   -scc{UTF-8|WIN|DOS}: Set the character set for console input/output.
   -scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}}: Set the character set of the list file.
   -scrc[CRC32|CRC64|SHA1|SHA256|*]: Set hash function for x, e, h commands.
   -sdel: delete files after compression
   -seml[.] : Send compressed package via email
   -sfx[{name}]: Create SFX compressed package
   -si[{name}] : Read data from standard input
   -slp: Set large page mode
   -slt: Display technical information of l(List) command
   -snh : store hard links as links
   -snl : store symbolic links as links
   -sni : Store NT security information
   -sns[-] : store NTFS alternate stream
   -so: write data to standard output
   -spd : disable wildcard matching of file names
   -spe : Eliminate duplication of root folders in extraction commands.
   -spf[2] : Use fully qualified file paths
   -ssc[-]: Set sensitive case mode
   -sse : Stop creating archive if some input files cannot be opened
   -ssp: Do not change the last access time of the source file when compressing the package
   -ssw: compress shared files
   -stl: Set the archive timestamp from the most recently modified file
   -stm{HexMask} : Set CPU thread affinity mask (hex number).
   -stx{Type}: exclude compressed package type
   -t{Type}: Set the type of compressed package
   -u[-][p#][q#][r#][x#][y#][z#] [!newArchiveName] : Update options
   -v{Size}[b|k|m|g] : Create volume
   -w[{path}]: Specify the working directory. An empty path means a temporary directory
   -x[r[-|0]]{@listfile|!wildcard} : Exclude file names.
   -y : Assume all queries are positive

Official website

For more installation and usage methods, you can visit the official website to learn: https://www.7-zip.org/ Or you can visit the simplified Chinese website: https://sparanoid.com/lab/7z/