How to Read Command Syntax

Learn how to interpret command syntax with these examples

In This Article

Jump to a Section

The syntax of a command is basically the rules for running the command. You need to know how to read syntax notation when learning how to use a command so you can execute it properly.

As you've probably seen here on Lifewire and maybe other websites, Command Prompt commands, DOS commands, and even many run commands are described with all sorts of slashes, brackets, italics, etc. Once you know what all of those marks refer to, you can look at any command's syntax and know right away what options are required and what options can be used with what other options.

Depending on the source, you might see slightly different syntax used to describe commands. We use a method historically used by Microsoft, and all command syntax we've ever seen on any site is extremely similar. But remember, you should follow the syntax key that pertains to the commands you're reading, and not assume that all websites and documentation use the exact same method.

Command Syntax Key

The following syntax key describes how each notation in a command's syntax is to be used. Feel free to reference this as we walk through the three examples below the table.

Command Syntax Reference Table
Notation Meaning
Bold Bold items must be typed exactly as they're shown, this includes any bold words, slashes, colons, etc.
Italic Italic items are items you must supply. Do not take an italic item literally and use it in the command as shown.
S p a c e s All spaces should be taken literally. If a command's syntax has space, use that space when executing the command.
[Text inside brackets] Any items inside a bracket are optional. Brackets aren't to be taken literally, so don't use them when executing a command.
Text outside brackets Any text not contained in a bracket is required. In the syntax of many commands, the only text not surrounded by one or more brackets is the command name itself.
{Text inside braces} The items within a brace are options, of which you must choose only one. Braces are not to be taken literally, so don't use them when executing a command.
Vertical | bar Vertical bars are used to separate items within brackets and braces. Do not take vertical bars literally—do not use them when executing commands.
Ellipsis ... An ellipsis means that an item can be repeated indefinitely. Do not type ellipsis literally when executing a command, and take care to use spaces and other required items as shown when repeating items.

Brackets are also sometimes referred to as square brackets, braces are sometimes referred to as squiggly brackets or flower brackets, and vertical bars are sometimes called pipes, vertical lines, or vertical slashes. Regardless of what you call them, none should ever be taken literally when executing a command.

Example #1: Vol Command

Here's the syntax for the vol command, a command available from the Command Prompt in all versions of the Windows operating system:

vol [drive:]

Vol command

The word vol is in bold, meaning it should be taken literally. It's also outside any brackets, meaning it's required. We'll take a look at brackets a few paragraphs down.

Following vol is a space. Spaces are to be taken literally, so when you're executing the vol command, put a space between vol and anything that might come next.

Brackets indicate that whatever is contained inside them is optional—whatever is in there is not required for the command to function but might be something you want to use, depending on what you're using the command for. Brackets are never to be taken literally, so never include them when executing a command.

Inside the brackets is the italicized word drive, followed by a colon in bold. Anything italicized is something you must supply, not take literally. In this case, a drive is referring to a drive letter, so you'll want to supply a drive letter here. Just as with vol, since : is in bold, it should be typed as shown.

Based on all of that information, here are some valid and invalid ways to execute the vol command and why:

vol

Valid: The vol command can be executed by itself because drive: is optional because it's surrounded by brackets.

vol d

Invalid: This time, the optional part of the command is being used, specifying drive as d, but the colon was forgotten. Remember, we know the colon accompanies the drive because it is included in the same set of brackets, and we know it should be used literally because it's bold.

vol e: /p

Invalid: The /p option wasn't listed in the command syntax, so the vol command doesn't run when using it.

vol c:

Valid: In this case, the optional drive: argument was used just as intended.

Example #2: Shutdown Command

The syntax listed here is for the shutdown command and is obviously much more complex than in the vol command example above. However, building on what you already know, there's actually very little more to learn here:

shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f] [/m \\computername] [/t xxx] [/d [p:|u:]xx:yy] [/c "comment"]

Shutdown command

Remember that items within brackets are always optional, items outside of brackets are always required, bold items and spaces are always literal, and italicized items are to be provided by you.

The big new concept in this example is the vertical bar. Vertical bars within brackets indicate optional choices. So in the example above, you can, but don't have to, choose to include one of the following options when executing a shutdown command: /i, /l, /s, /r, /g, /a, /p, /h, or /e. Like brackets, vertical bars exist to explain command syntax and are not to be taken literally.

The shutdown command also has a nested option in [/d [p:|u:]xx:yy]—basically, an option within an option.

Like with the vol command in the first example, here are some valid and invalid ways to use the shutdown command:

shutdown /r /s

Invalid: The /r and /s options can't be used together. These vertical bars indicate choices, of which you can choose only one.

shutdown /s p:0:0

Invalid: Using /s is perfectly fine but the use of p:0:0 is not because this option is available only with the /d option, which we forgot to use. The correct usage would have been shutdown /s /d p:0:0.

shutdown /r /f /t 0

Valid: All options were used correctly this time. The /r option was not used with any other choice within its set of brackets, and the /f and /t options were used as described in the syntax.

Example #3: Net Use Command

For our final example, let's look at the net use command, one of the net commands. Its syntax is a little messy, so we've abbreviated it below to make explaining it a bit easier (see the full syntax here):

net use [{devicename | *}] [\\computername\sharename [{password | *}]] [/persistent:{yes | no}] [/savecred] [/delete]

net use command in Windows

The net use command has two instances of a new notation: the brace. A brace indicates that one, and only one, of the choices, separated by one or more vertical bars, is required. This is unlike the bracket with vertical bars that indicates optional choices.

Let's look at some valid and invalid uses of net use:

net use e: * \\server\files

Invalid: The first set of braces means you can specify a devicename or use the wildcard character * - you can't do both. Either net use e: \\server\files or net use * \\server\files would have been valid ways to execute net use in this case.

net use * \\appsvr01\source 1lovet0visitcanada /persistent:no

Valid: We correctly used several options in this execution of net use, including one nested option. We used the * when required to choose between it and specifying a devicename, we specified a share [source] on a server [appsvr01], and then chose to specify a {password} for that share, 1lovet0visitcanada, instead of forcing net use to prompt us for one {*}. We also decided not to allow this new shared drive to be automatically reconnected next time we start the computer [/persistent:no].

net use /persistent

Invalid: In this example, we chose to use the optional /persistent switch but forgot to include the colon next to it and also forgot to choose between the two required options, yes or no, between the braces. Executing net use /persistent:yes would have been a valid use of net use.

Was this page helpful?