# 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 '}') 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:

- '*' means a sequence of arbitrary characters.
- '?' means any character.

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.

Slash ('\') at the end of path means directory. Without Slash ('\') at the end of path it can refer to both file and 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 space, tab or new line symbol(s). Wildcards or filenames with spaces must be quoted.

For list files 7-Zip uses OEM (DOS) encoding.

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".

## Short and Long File Names

7-Zip supports short file names (like FILENA~1.TXT) in some cases. But it's strongly recommended to use real (long) file names.