Linux/Unix man page syntax conventions

[亡魂溺海] 提交于 2019-11-26 15:38:29

问题


In man pages I come across various syntaxes to write Linux/Unix commands, which include square brackets, angular brackets, hyphens (-) and double hyphens (--) in various combinations. Does anyone know the meaning of these syntax conventions?

[ ]
< >
[< >]
[--]
-
--
[< >...]

回答1:


Square Brackets [ ]

The square brackets ( [ ] ) indicate that the enclosed element (parameter, value, or information) is optional. You can choose one or more items or no items. Do not type the square brackets themselves in the command line.

Example: [global options], [source arguments], [destination arguments]

Angle Brackets < >

The angle brackets ( < > ) indicate that the enclosed element (parameter, value, or information) is mandatory. You are required to replace the text within the angle brackets with the appropriate information. Do not type the angle brackets themselves in the command line.

Example: -f [set the File Name variable], -printer <printer name>, -repeat <months> <days> <hours> <minutes>, date access <mm/dd/yyyy>

In Unix-like systems, the ASCII hyphen–minus is commonly used to specify options. The character is usually followed by one or more letters. An argument that is a single hyphen–minus by itself without any letters usually specifies that a program should handle data coming from the standard input or send data to the standard output. Two hyphen–minus characters ( -- ) are used on some programs to specify "long options" where more descriptive option names are used. This is a common feature of GNU software.

Just do 'ls --help' and look at the options, it should be obvious to you.

 -A, --almost-all           do not list implied . and ..
     --author               with -l, print the author of each file
 -b, --escape               print octal escapes for nongraphic characters
     --block-size=SIZE      use SIZE-byte blocks
 -B, --ignore-backups       do not list implied entries ending with ~
 -c                         with -lt: sort by, and show, ctime (time of last
                              modification of file status information)
                              with -l: show ctime and sort by name
                              otherwise: sort by ctime'
 -C                         list entries by columns
     --color[=WHEN] 



回答2:


There is also uncommon {} brackets used which from my search is for a required options that can be specified in mutually exclusive ways, ex {-A|--almost-all}.

 "{}" are used in conjunction with a vertical bar to
indicate cases where exactly one of the specified options may be used

https://groups.google.com/forum/#!topic/comp.unix.programmer/XOr31SgvvS8



来源:https://stackoverflow.com/questions/23242493/linux-unix-man-page-syntax-conventions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!