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 '}') means that instead that Expression (including braces) must be used 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:
7-Zip doesn't uses system wildcard mask parser, and 7-Zip doesn't follow that archaic rule, when *.* means any file. 7-Zip treats *.* as any file that have extension. To process all files you must use * 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 "." means characters |
The default wildcard "*" will be used if there is no filename/wildcard in command line.
Restrictions for wildcards and filenames for archiving files:
Examples:
Dir1\*.cpp | OK |
c:\Dir1\*.cpp | ILLEGAL: path contains disk name |
Dir1\Dir2\g?.txt | OK |
Dir1\D?r2\file1.txt | ILLEGAL: there is a wildcard char in non last part |
These restrictions do not act to filenames and directory names used not as archiving files.
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 space, tab or new line symbol(s). Wildcards or filenames with spaces must be quoted.
Multiple list files are supported.
For example, if contents of file "listfile.txt" is the following:
"My programs\*.cpp" Src\*.cpp
then command
7z a -tzip archive.zip @listfile.txt
adds to archive "archive.zip" all "*.cpp" files from directories "My programs" and "Src".