Click here to Skip to main content
13,864,533 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 29 Dec 2018
Licenced CPOL

7-Zip for Gearheads

, 29 Dec 2018
Rate this:
Please Sign up or sign in to vote.
When the command-line help falls short, we improvise.


For several years, I've used the 7-Zip command line interface, 7z.exe for my daily backup needs. Continuing as I did long ago with its predecessor, WizZip, I constructed a batch file to automate regularly repeated backup chores, such as making backups of source code and program output directories. Today, I decided that I needed a companion script to restore files from an archive

In the process, I decided to put an end to my regular (and frequent) forays into the online help file that comes with the graphical user interface, 7zFM.exe, by supplementing the help provided by 7z.exe when you run it without parameters. Soon after I started using 7Zip regularly, I saved that output into a text file, which I put into a handy directory where I keep files for the command line system utilities that I use regularly, but not enough to have committed their command line arguments to memory. To ensure that I always have access to it,, even when I work on site, that directory is mirrored to the OneDrive directory associated with the Microsoft account that I use for work.


As is the case with most system utilities, the help text generated when the utility is run without arguments is great if you know the minutiae pretty well, and just need a refresher from time to time, but it falls short as a true reference page. Thankfully, it usually needs only a few additions to make it vastly more useful as a true freestanding help document.

Using the code

Without further ado, following is my improved help.

            Manual Page for 7z.exe, the 7-Zip Command Line Interface

7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04

Usage: 7z<command />

  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

  --                                             : Stop switches parsing
  -ai[r[-|0]]{@listfile|!wildcard}               : Include archives

                                                       r    = Modify as indicated for freestanding R switch. (See below.)
                                                       @    = Filespec is the name of a list file.
                                                       !    = Filespec is a glob.

  -ax[r[-|0]]{@listfile|!wildcard}               : eXclude archives
  -ao{a|s|t|u}                                   : set Overwrite mode

                                                       a    = All (unconditional)
                                                       s    = Skip existing files
                                                       t    = Rename existing file, e. g., if name.txt exists, rename it name_1.txt
                                                       u    = Rename extracted file, e. g., if name.txt exists, extract as name_1.txt

  -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 (See 7zFM help file.)
  -bt                                            : show execution time statistics
  -i[r[-|0]]{@listfile|!wildcard}                : Include filenames

                                                       r    = Modify as indicated for freestanding R switch. (See below.)
                                                       @    = Filespec is the name of a list file.
                                                       !    = Filespec is a glob.

  -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 (The 7zFM help file asserts that this works with E and X commands.
                                                                          Though it may do so, it doesn't behave as I would expect.)

                                                       bare             = Enable recursion, presumably w/o respect to glob (wild card mask)
                                                       - (e. g., -r-)   = Disable recursion
                                                       0 (e. g., -r0)   = Recurse subdirectories, respecting the glob

  -sa{a|e|s}                                     : set Archive name mode

                                                        a   = Always append extension per specified archive type (requires -t switch)
                                                        e   = Use name exactly as specified on command line
                                                        s   = Use extension if supplied, else add per specified archive type (requires -t switch)

  -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 (See 7zFM help file.)
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options (See 7zFM help file.)
  -v{Size}[b|k|m|g]                              : Create volumes (See 7zFM help file.)
  -w[{path}]                                     : assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]{@listfile|!wildcard}                : eXclude filenames (See 7zFM help file.)
  -y                                             : assume Yes on all queries


Points of Interest

Of particular interest are the additions covering the R and I switches, especially my observation that the freestanding R switch seems not to work as advertised. Thankfully, in combination with the I switch, it works just fine.

For your convenience, I put a copy of the original help file in the article download. Though the file is quite small, it's a ZIP, since CP doesn't support text files.


On Saturday, 29 December 2018, the article was submitted for publication.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

David A. Gray
Software Developer (Senior)
United States United States
I deliver robust, clean, adaptable, future-ready applications that are properly documented for users and maintainers. I have deep knowledge in multiple technologies and broad familiarity with computer and software technologies of yesterday, today, and tomorrow.

While it isn't perceived as sexy, my focus has always been the back end of the application stack, where data arrives from a multitude of sources, and is converted into reports that express my interpretation of The Fundamental Principle of Tabular Reporting, and are the most visible aspect of the system to senior executives who approve the projects and sign the checks.

While I can design a front end, I prefer to work at the back end, getting data into the system from outside sources, such as other computers, electronic sensors, and so forth, and getting it out of the system, as reports to IDENTIFY and SOLVE problems.

When presented with a problem, I focus on identifying and solving the root problem for the long term.

Specialties: Design: Relational data base design, focusing on reporting; organization and presentation of large document collections such as MSDS libraries

Development: Powerful, imaginative utility programs and scripts for automated systems management and maintenance

Industries: Property management, Employee Health and Safety, Services

Languages: C#, C++, C, Python, VBA, Visual Basic, Perl, WinBatch, SQL, XML, HTML, Javascript

Outside Interests: Great music (mostly, but by no means limited to, classical), viewing and photographing sunsets and clouds, traveling by car on small country roads, attending museum exhibits (fine art, history, science, technology), long walks, especially where there is little or no motor traffic, reading, especially nonfiction and thoughtfully written, thought provoking science fiction

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190214.1 | Last Updated 30 Dec 2018
Article Copyright 2018 by David A. Gray
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid