Linux / Unix手册页语法约定

问题描述 投票:16回答:2

man页面中,我遇到了各种语法来编写Linux / Unix命令,其中包括方括号,尖括号,连字符(-)和双连字符(--)的各种组合。有谁知道这些语法约定的含义?

[ ]
< >
[< >]
[--]
-
--
[< >...]
linux unix man
2个回答
34
投票

方括号 [ ]

方括号([])表示包含的元素(参数,值或信息)是可选的。您可以选择一个或多个项目或不选择任何项目。不要在命令行中键入方括号。

示例:[global options], [source arguments], [destination arguments]

角支架<>

尖括号(<>)表示包含的元素(参数,值或信息)是必需的。您需要使用适当的信息替换尖括号内的文本。请勿在命令行中键入尖括号。

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

在类Unix系统中,ASCII连字符 - 减号通常用于指定选项。角色通常后跟一个或多个字母。一个单独的连字符 - 减去其自身没有任何字母的参数通常指定程序应处理来自标准输入的数据或将数据发送到标准输出。在某些程序中使用两个连字符 - ( - )来指定使用更多描述性选项名称的“长选项”。这是GNU软件的常见功能。

只要做'ls --help'并查看选项,它应该是显而易见的。

 -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] 

10
投票

还有一些不常见的{}括号,我搜索的是一个必需的选项,可以互斥的方式指定,例如{-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

© www.soinside.com 2019 - 2024. All rights reserved.