Site icon VipsPatel

How to Read Windows Command Line Syntax

command-line-syntax-iconIf you are using a Windows PC, you probably have seen or used a command-line to get something done on your Windows PC. If you ever need help with some command, there are plenty of sites to help you with the syntax and usage of the commands. But, unless you know how to read that command line syntax, that help is nothing but a gibberish string.

For instance, if you check the official command line reference for the command attrib, you will see the command line syntax something like this.

ATTRIB [{+R|-R}] [{+A|-A}] [{+S|-S}] [{+H|-H}] [[drive:][path] filename] [/S[/D]]

As you can see, the above command line syntax contains all sorts of variations like upper and lower case, and special characters like spaces, brackets (“[ ]“), braces (“({})”), and pipes (” | “). The above command line doesn’t make any sense to an untrained eye, but it informs you of the different parameters that you can use with the attrib command.

How to Read Command Syntax

A command syntax is nothing but the rules which govern how a command can be used or run. Unless you know how to read the command line syntax, you can’t use or understand the commands properly or to their full potential. So in this basic tutorial, let us hop on and learn some basics on how to read command line syntax. As per the example, you can take the above “attrib” command and use the information below to interpret that command.

Special Character “+”: Whenever you use the special character + in front of an item or parameter, it means that you are setting up that parameter for the task you are doing.

For instance, in the above attrib command, whenever you use the parameter +R in the command, you are setting the read-only mode for a selected file or folder.

Special Character “-“: Whenever you use the special character - in front of an item or parameter, it means that you are clearing up that parameter for the task you are doing.

For instance, in the above attrib command, whenever you use the parameter -R in the command, you are removing the read-only mode for a selected file or folder.

Characters in Caps: In command line syntax, characters represented in capitals are what users should type exactly. When I say characters, it includes all the numbers, special characters and letters.

For example, in the above attrib command, the base command ATTRIB and the switches like -R, +A, /S, etc., should be used as is without any modifications whatsoever. So the valid command looks something like this,

ATTRIB +R

but not like this, which eliminates the special character “+”.

ATTRIB R

Characters in Smalls: Whenever you see small character representation, it just means that the user should supply the information required for the command to execute properly.

For example, in the above attrib command, you need to supply the information like the drive and the file path in the place of [[drive:][path] filename]. Once supplied, the command looks something like this.

ATTRIB C:folderfile.txt

Pipes (Vertical Bars): Pipes or vertical bars are used to show the various parameters that you can use inside the brackets or braces. It has the same meaning as “either…or,” which means only one of the parameters can be used. Pipes or vertical bars is for illustration only and should not be used with actual commands.

For example, in the above attrib command, you can see that the switches +R and -R are separated by a vertical bar, which means that they are two different parameters and only one of them (either +R or -R) can be used in the actual command.

Braces (“{ }”): Any items or parameters inside braces are a set of choices where a user should choose one, i.e. you can choose one parameter between a group of parameters inside the braces. Also, you shouldn’t use braces with actual commands.

For example, the command syntax {+A | -A} suggests that you can either use the switch +A or -A in the actual command but not both of them at the same time, as they belong to the same group. So the valid command looks something like this,

ATTRIB +A

but not like this, which uses both options at the same time.

ATTRIB +A -A

Brackets (“[ ]“): Any items or parameters inside brackets are optional, i.e. it is up to you to use those parameters or not. Also, you shouldn’t use brackets with actual commands.

For example, in the above attrib command, the syntax [{+R|-R}] suggests that you can either use the optional parameters or not (also, keep the braces in mind). So, any of the below commands are valid.

ATTRIB +R

or

ATTRIB

Spaces: Even spaces have meaning in command syntax. If you find a space in the command syntax, then you should use it while executing the actual command.

For example, in the above attrib command, you shouldn’t eliminate any of the spaces. So, a valid command will look something like this,

ATTRIB +R -H

but not like this, which eliminates the spaces.

ATTRIB+R-H

Text Outside Brackets: Just like Spaces, any text outside of the brackets must be used and should be used “as is” while executing the commands.

For example, in the above attrib command, the base command ATTRIB must be used and should be used as is. So the valid command looks something like this,

ATTRIB +R -H C:folderfile.txt

and not like this, which eliminates the usage of the text outside brackets.

+R -H C:folderfile.txt

Ellipsis (“…”): Ellipsis is not so common in any syntax, but if you see an ellipsis, then it means that the item or parameter can be repeated endlessly.

Conclusion

Knowing how to interpret command line syntax is very helpful for understanding and using the command references found in the official documentation and on the Internet. Sure, it may take some time to get hold of these syntax rules, but it is worth it.

Don’t forget to share your thoughts using the comment form below.

The post How to Read Windows Command Line Syntax appeared first on Make Tech Easier.



Exit mobile version