How to read Unix usage

I did some searching, but I cannot find documentation on how Unix usage works. I know something (mostly through trial and error) but, for example, how do I know that

/usr/bin/ls  [-aAbcCdeEfFghHilLmnopqrRstuvVx1@] [file]...

means that you can include more than one option? That is,

ls -la

Where is some documentation on what the usage syntax is?


Solution 1:

It's true there is no RFC or anything, but you don't go too far off base if you stick to these guidelines:

  1. Anything in angle brackets < > means the option is required:
    <foo>

  2. Anything in square brackets [ ] means the option is optional:
    [bar]

  3. Options separated by a pipe | means those are the valid values:
    --baz=one|two|three

  4. Single-letter options start with one dash:
    -a

  5. Multi-letter options start with two dashes:
    --foo-bar

  6. (based on #4) A single dash with multiple letters usually means the union of those individual single-letter options rather than a multi-letter option. Not all commands support that kind of union. Example:
    -aAbBcC is the same as -a -A -b -B -c -C

Solution 2:

There is no strict structure for man pages, but the following covers most commands.

From MANUAL PAGES(5), BSD File Formats Manual, section "MANUAL PAGE SYNTAX":

In manual page syntax, anything in a normal text font is required text. Anything in a boldface font is a flag or a subcommand. Anything underlined is a user-specified argument such as a filename.

Any argument surrounded by brackets is considered to be optional. For example, [ filename ] would indicate an optional filename argument.

Flags, arguments, or subcommands separated by a vertical separator (|) are mutually exclusive. For example, if -a turns on an option and -b turns off the option, the syntax for this command might be -a | -b.

In some cases, you may even see entire groups of arguments wrapped with brackets and separated by a vertical separator. This is one way of showing that a command has more than one valid syntax. In other manual pages, this is expressed by having multiple lines in the synopsis, each of which begins with the command name. The separated format is more common (and more readable), but is not always possible for commands with particularly complex syntax.

Finally, the most important notational convention is the use of the ellipsis (...). This indicates that additional arguments may be added at this point.

Solution 3:

The usage lines don't follow anything consistent.

You should use man ls or info ls to get a more consistent level of information.