How To Read Command Syntax

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 use it properly.
As you’ve probably seen on my site and maybe others, 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.
Note: Depending on the source, you might see slightly different syntax when used to describe commands. I used a method that Microsoft has historically used but all command syntax that I’ve every seen on any site is extremely similar to what I use.
The Command Syntax Key at the bottom of the page describes how each notation in a command’s syntax is to be used so feel free to reference it as we walk through three examples:
Example #1: Vol Command
vol [drive:]
This is the syntax for the vol command, a command available from the Command Prompt in all versions of the Windows operating system.
The word vol is in bold, meaning that it should be taken literally. It’s also outside of any brackets, meaning it’s required. We’ll take a look at brackets a few paragraphs down.
Following vol is a space. Spaces in a command’s syntax are to be taken literally so when you’re executing the vol command, you will need to 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, 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 with 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 does not run when using it.

vol c:

Valid: In this case, the optional drive: argument was used just as intended.
Example #2: Shutdown Command
shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f] [/m computername] [/t xxx] [/d [p:|u:]xx:yy] [/c “comment]
The syntax listed above for the shutdown command is obviously much more complex than in the first example but building on what you already know, there’s actually very little more to learn here.
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 Example #1 above, here are some valid and invalid ways to use the shutdown command:

shutdown /r /s

Invalid: The /r and /s options can not 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 within the /d option, which I 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
net use [{devicename | *}] [computernamesharename [{password | *}]] [/persistent:{yes | no}] [/savecred] [/delete]
For our final example, let’s look at the net use command, one of the net commands. The net use command syntax is a little messy so I’ve abbreviated it to make explaining it a bit easier. You can see the full syntax here.
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: * serverfiles

Invalid: The first set of braces mean that you can specify a devicename or use the wildcard character * – you can’t do both. Either net use e: serverfiles or net use * serverfiles would have been valid ways to execute net use in this case.

net use * appsvr01source 1lovet0visitcanada /persistent:no

Valid: I correctly used several options in this execution of net use, including one nested option. I used the * when required to choose between it and specifying a devicename, I 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 me for one {*}. I also decided not to allow this new shared drive to be automatically reconnected next time I start my computer [/persistent:no].

net use /persistent

Invalid: In this example, I chose to use the optional /persistent switch but I 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.

Command Syntax Key

Notation Meaning
Bold Bold items must typed exactly as they are shown, this includes any bold words, slashes, colons, etc.
Italic Italic items are items that 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 a space, use that space when executing the command.
[Text inside brackets] Any items inside a bracket are optional. Brackets are not 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.

Note: 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 what you call them, none should ever be taken literally when executing a command.


TOP