如何阅读命令行格式文档 linux unix

本文通过git帮助文档,详细解读命令行工具中各种符号的含义,包括命令名称、可选内容、参数、选项、重复参数以及选项的使用规则,旨在帮助读者更好地理解和使用命令行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用命令行工具的时候,看文档都会遇到命令格式。这样就需要看明白各种符号的含义。

下面就以git帮助文档为例解释格式含义。git版本:2.20.1.windows.1。

敲入:

git status -h

可以得到帮助文档如下:

usage: git status [<options>] [--] <pathspec>...

    -v, --verbose         be verbose
    -s, --short           show status concisely
    -b, --branch          show branch information
    --show-stash          show stash information
    --ahead-behind        compute full ahead/behind values
    --porcelain[=<version>]
                          machine-readable output
    --long                show status in long format (default)
    -z, --null            terminate entries with NUL
    -u, --untracked-files[=<mode>]
                          show untracked files, optional modes: all, normal, no. (Default: all)
    --ignored[=<mode>]    show ignored files, optional modes: traditional, matching, no. (Default: traditional)
    --ignore-submodules[=<when>]
                          ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)
    --column[=<style>]    list untracked files in columns
    --no-renames          do not detect renames
    -M, --find-renames[=<n>]
                          detect renames, optionally set similarity index
    --show-ignored-directory
                          (DEPRECATED: use --ignore=matching instead) Only show directories that match an ignore pattern name.
    --no-lock-index       (DEPRECATED: use `git --no-optional-locks status` instead) Do not lock the index

其中,第一行:

git status [<options>] [--] <pathspec>...

若名称是直接写出来的,没有方括号,也没有尖括号,也没有-或--,例如,"git", "status",就是命令或子命令的名称。

如果有方括号,即[]括住的内容,就表示是可选的内容,即可以不写的内容。

尖括号,即<>括住的内容表示参数。

省略号...,表示之前的内容可以重复多个。这里就表示,<pathspec>参数可以使用多个。

这里有个--,这个是用来分割选项和位置参数的。这个之前的是选项,这个之后的是位置参数。这个--被方括号括住,表示这个可以不用写。

 

其中:

-b, --branch

用--,或-开头的内容就是选项。通常,--之后跟的选项的全名,-之后跟的是选项的缩略名。

 

敲入

git push -h

得到git push的文档如下:

usage: git push [<options>] [<repository> [<refspec>...]]

    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
    --repo <repository>   repository
    --all                 push all refs
    --mirror              mirror all refs
    -d, --delete          delete refs
    --tags                push tags (can't be used with --all or --mirror)
    -n, --dry-run         dry run
    --porcelain           machine-readable output
    -f, --force           force updates
    --force-with-lease[=<refname>:<expect>]
                          require old value of ref to be at this value
    --recurse-submodules[=(check|on-demand|no)]
                          control recursive pushing of submodules
    --thin                use thin pack
    --receive-pack <receive-pack>
                          receive pack program
    --exec <receive-pack>
                          receive pack program
    -u, --set-upstream    set upstream for git pull/status
    --progress            force progress reporting
    --prune               prune locally removed refs
    --no-verify           bypass pre-push hook
    --follow-tags         push missing but relevant tags
    --signed[=(yes|no|if-asked)]
                          GPG sign the push
    --atomic              request atomic transaction on remote side
    -o, --push-option <server-specific>
                          option to transmit
    -4, --ipv4            use IPv4 addresses only
    -6, --ipv6            use IPv6 addresses only

 

这里,--signed选项格式如下:

--signed[=(yes|no|if-asked)]

这里,首先有一个方括号,表示可以直接用--signed,后面的东西可以没有。

这里,|表示或,即yes,no,if-asked要选择其中一个。使用圆括号,而不是方括号括住,表示这三个中一定要选一个,不能一个都不选。圆括号的意思,就是必须有,区别于方括号,可选。

 

 

参考文档:

http://docopt.org/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值