Understanding command syntax
Whenever you look up a command in the Utilities Reference, you'll see a syntax statement that summarizes how you can use the command.
For most commands, this statement consists of the following components:
- The name of the command to be executed. This may be the name of an executable program, such as a utility, or it may be the name of a command built into the shell.
- The specific behavior that you want to invoke for the command. Options typically consist of an alphanumeric character preceded by a hyphen (e.g. -c). Some options take an argument (e.g. -n number). If you specify an option that takes an argument, you must include its argument as well.
- Data the command requires (e.g. a filename). If a command lets you enter multiple operands, they're usually processed in the order you list them. Unlike options, operands aren't preceded by a hyphen (e.g. less my_file).
The entries in the Utilities Reference use some special symbols to express the command syntax:
- You can specify one or more instances of the previous element. For example, in the
utility syntax, the ellipsis after the operand file
indicates that you can specify more than one file on the command line:
less myfile1 myfile2
- [ ]
- The enclosed item is optional.
- You can use only one of the items (e.g. -a|-f).
You don't actually type these symbols when you invoke the command. For instance, the syntax description for less is given as follows:
less [-[+]aBcCdeEfimMnNqQrsSuUw] [-b n] [-x n] [-[z] n] [-h n] [-j n] [-p pattern] [-y n] [-[oO] logfile] [-t tag] [-T tagsfile] [+ cmd] [file...]
You can combine multiple options that don't take an argument. The -aBcCdeEfimMnNqQrsSuUw notation is shorthand for -a -B -c -C -d and so on.
If an argument to a command starts with a hyphen, you can signal the end of the options by using a double hyphen:
ls -l -- -my_file
For more information, see Utility Conventions in the Utilities Reference.