Report issue Add example

7z

An open-source archive software with a high compression ratio.

Installation

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

# Ubuntu systems
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

Examples

Common scenarios: extraction, compression, and viewing (archive contents).

  1. Extract the archive text.7z to the current directory.
7z x text.7z
  1. Extract the archive text.7z to a specific directory (/home/text).
# Note: -o is used to specify the output directory. There is no space between -o and the directory path.
7z x text.7z -r -o/home/text
  1. Extract specific files/folders (dir1/dir2 and dir1/file1) from text.7z to a specific directory (/home/text), maintaining the original path structure.
# Note: dir1/dir2 and dir1/file1 are the paths of files or folders within the archive.
7z x text.7z dir1/dir2 dir1/file1 -o/home/text
  1. Compress the directory /home/text into text.7z.
7z a text.7z -r /home/text
  1. View the contents of text.7z without extracting.
7z l text.7z

Help Information Translation

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

<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 in archive
  x : eXtract files with full paths

<Switches>
  -- : Stop switches parsing (allows using filenames starting with - or @)
  -ai[r[-|0]]{@listfile|!wildcard} : Include archives
  -ax[r[-|0]]{@listfile|!wildcard} : Exclude archives
  -ao{a|s|t|u} : Set Overwrite mode
    -aoa Overwrite all existing files without prompt
    -aos Skip extracting of existing files
    -aou Auto rename extracted file (e.g., name.txt will be renamed to name_1.txt)
    -aot Auto rename existing file (e.g., name.txt will be renamed to name_1.txt)
  -an : Disable archive_name field parsing (must be used with -ai switch)
  -bb[0-3] : Set output log level
    -bb0 Disable logging (default)
    -bb1 or -bb Show names of processed files in log
    -bb2 Show names of skipped files in log (for "Extract" operation) and repackaged files (for "Add" / "Update" operations)
    -bb3 Show additional information for "Add" / "Update" operations (analysis, copy)
  -bd : Disable progress indicator
  -bs{o|e|p}{0|1|2} : Set output stream for output/error/progress lines
    o stdout
    e stderr
    p progress
    0 disable stream
    1 redirect to stdout
    2 redirect to stderr
  -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), -mx0 (no compression)
  -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 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 filenames
  -spe : Eliminate duplication of root folder for extract command
  -spf[2] : Use fully qualified file paths
  -ssc[-] : Set sensitive case mode
  -sse : Stop archive creation if any input files cannot be opened
  -ssp : Do not change last access time of source files when archiving
  -ssw : Compress shared files
  -stl : Set archive timestamp from the most recently modified file
  -stm{HexMask} : Set CPU thread affinity mask (hexadecimal numbers)
  -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 working directory. Empty path means a temporary directory
  -x[r[-|0]]{@listfile|!wildcard} : Exclude filenames
  -y : Assume Yes on all queries

Official Website

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