Command Line Syntax
7z <command> [<switch>...] <base_archive_name> [<arguments>...]
<arguments> ::= <switch> | <wildcard> | <filename> | <list_file> <switch>::= <switch_symbol><switch_characters>[<option>] <switch_symbol> ::= '/' | '-' <list_file> ::= @{filename}
Expressions in square brackets (between '[' and ']') are optional.
Expressions in curly braces ('{' and '}') mean that instead of that Expression (including braces), the user must substitute some string.
Expression
expression1 | expression2 | ... | expressionN
means that any (but only one) from these expressions must be specified.
Commands and switches can be entered in upper or lower case.
Command is the first non-switch argument.
The "base_archive_name" must be the first filename on the command line after the command.
The switches and other filenames can be in any order.
Wildcards or filenames with spaces must be quoted:
"Dir\Program files\*" Dir\"Program files"\*
Switch options can be combined to save command line length. However, some switch options take optional string arguments and therefore, must be the last option in a combined argument token string because 7-Zip accepts the rest of the argument token as the optional argument.
7-Zip uses wild name matching similar to Windows 95:
- '*' means a sequence of arbitrary characters.
- '?' means any character.
7-Zip doesn't use the system wildcard parser. 7-Zip doesn't follow the archaic rule by which *.* means any file. 7-Zip treats *.* as matching the name of any file that has an extension. To process all files, you must use a * wildcard.
Examples:
*.txt | means all files with an extension of ".txt" |
?a* | means all files with a second character of "a" |
*1* | means all names that contains character "1" |
*.*.* | means all names that contain two at least "." characters |
The default wildcard "*" will be used if there is no filename/wildcard in the command line.
Slash ('\') at the end of a path means a directory. Without a Slash ('\') at the end of the path, the path can refer either to a file or a directory.
List file
You can supply one or more filenames or wildcards for special list files (files containing lists of files). The filenames in such list file must be separated by new line symbol(s).
For list files, 7-Zip uses UTF-8 encoding by default. You can change encoding using -scs switch.
Multiple list files are supported.
For example, if the file "listfile.txt" contains the following:
My programs\*.cpp Src\*.cpp
then the command
7z a -tzip archive.zip @listfile.txt
adds to the archive "archive.zip" all "*.cpp" files from directories "My programs" and "Src".
Short and Long File Names
7-Zip supports short file names (like FILENA~1.TXT) in some cases. However, it's strongly recommended to use only the real (long) file names.
Other documents on this site:
- 7-Zip Manual /lzma.txt
- 7-Zip Manual /src-history.txt
- 7-Zip Manual /readme.txt
- 7-Zip Manual /7zC.txt
- 7-Zip Manual /License.txt
- 7-Zip Manual /copying.txt
- 7-Zip Manual /Methods.txt
- 7-Zip Manual /unRarLicense.txt
- 7-Zip Manual /7zFormat.txt
- 7-Zip Start Page
- Command Line Syntax
- Command Line Version User's Guide
- Exit Codes from 7-Zip
- -ax (Exclude archive filenames) switch
- -y (assume Yes on all queries) switch
- -sa (set Archive name mode) switch
- -slp (Set Large Pages mode) switch
- -p (set Password) switch
- -stl (Set archive timestamp from the most recently modified file) switch
- -sfx (Create SFX archive) switch
- -ssc (Set Sensitive Case mode) switch
- -scrc (Set hash function) switch
- -ai (Include archive filenames) switch
- -o (set Output directory) switch
- -si (read data from stdin) switch
- -r (Recurse subdirectories) switch
- -ssw (Compress files open for writing) switch
- -w (set Working directory) switch
- -so (write data to stdout) switch
- -i (Include filenames) switch
- -t (set Type of archive) switch
- -stx (Exclude archive type) switch
- -spf (Use fully qualified file paths) switch
- Command Line Switches
- -scc (Set charset for console input/output) switch
- -sdel (Delete files after including to archive) switch
- -m (Set compression Method) switch
- -slt (Show technical information) switch
- -u (Update options) switch
- -ao (Overwrite mode) switch
- -x (Exclude filenames) switch
- -v (Create Volumes) switch
- -scs (Set charset for list files) switch
- -an (Disable parsing of archive_name) switch
- -bb (Set output log level) switch
- -spf (Use fully qualified file paths) switch
- -sns (Store NTFS alternate Streams) switch
- -- (Stop switches parsing) switch
- -sni (Store NT security information) switch
- d (Delete) command
- x (Extract with full paths) command
- a (Add) command
- b (Benchmark) command
- e (Extract) command
- rn (Rename) command
- Command Line Commands
- h (Hash) command
- u (Update) command
- t (Test integrity of archive) command
- l (List contents of archive) command
- Menu Items and Shortcut Keys
- 7-Zip File Manager
- Options Dialog Box
- About Dialog Box
- Benchmark
- Plugins
- Add to Archive Dialog Box
- Extract Dialog Box
- 7-Zip Plugin
- Thanks
- License for use and distribution
- General Information
- Frequently Asked Questions (FAQ)
- Supported formats
- Performance
- 7z Format