Usage 语法说明
Unix/Linux 命令帮助(--help)通常采用一种约定俗成的语法描述命令格式。理解这些符号后,大多数命令的 Usage 都可以快速读懂。
| 语法 | 含义 | 示例 | |
|---|---|---|---|
[] | 可选参数(Optional) | [-a] | |
<> | 占位符(有些程序使用) | <file> | |
... | 可以出现多个 | file... | |
| ` | ` | 二选一 | json | xml |
-- | 选项结束 | rm -- -file | |
-a | 短参数 | tree -a | |
--all | 长参数 | git --version | |
[directory ...] | 可指定多个目录 | tree dir1 dir2 dir3 |
以 tree 命令为例,在 macOS 或者 Linux 上输入 tree --help 命令,会得到如下帮助信息:
tree --help
usage: tree [-acdfghilnpqrstuvxACDFJQNSUX] [-L level [-R]] [-H [-]baseHREF]
[-T title] [-o filename] [-P pattern] [-I pattern] [--gitignore]
[--gitfile[=]file] [--matchdirs] [--metafirst] [--ignore-case]
[--nolinks] [--hintro[=]file] [--houtro[=]file] [--inodes] [--device]
[--sort[=]name] [--dirsfirst] [--filesfirst] [--filelimit[=]#] [--si]
[--du] [--prune] [--charset[=]X] [--timefmt[=]format] [--fromfile]
[--fromtabfile] [--fflinks] [--info] [--infofile[=]file] [--noreport]
[--hyperlink] [--scheme[=]schema] [--authority[=]host] [--opt-toggle]
[--compress[=]#] [--condense] [--version] [--help]
[--] [directory ...][] 表示什么
例如:
[-a]表示:-a 可以写,也可以不写,因此,下面都合法:
tree -a
tree[-L level [-R]]
意思是:
-L是可选level是必须提供的参数-R又是可选
因此,下面都合法:
tree -L 1
tree -L 1 -R
tree -L 1 -R -a[directory ...]
表示:可以提供 0 个、1 个或多个目录,例如:
# 当前目录
tree
# 指定一个目录
tree src
# 指定多个目录
tree src docs--
表示:后面的内容全部认为是文件名,而不是参数。假如目录叫 -abc:
tree -- -abc否则,
tree -abc程序会误认为:
-a
-b
-c是三个参数,而不是一个目录名。