Linux help命令介绍
help命令是一个内置的shell命令,用来显示shell内置命令的帮助信息。它可以列出所有的内置命令,也可以显示某个内置命令的用法和选项。help命令只能显示内置命令的帮助信息,如果要查看其他命令的帮助信息,可以使用man或info命令。
Linux help命令适用的Linux版本
help命令是一个通用的Linux命令,适用于所有的Linux发行版,不需要安装。它是bash shell的一部分,所以只能在bash shell中使用。如果你使用的是其他的shell,比如zsh或fish,你可能需要使用其他的命令来查看内置命令的帮助信息,比如zsh的run-help命令或fish的help命令。
Linux help命令的基本语法
help命令的基本语法如下:
help [选项] [命令]
Linux help命令的常用选项或参数说明
help命令的常用选项或参数如下:
选项 | 参数 | 说明 |
---|---|---|
-d | 命令 | 显示命令的简短描述 |
-m | 命令 | 显示命令的帮助信息,使用man风格的格式 |
-s | 命令 | 显示命令的帮助信息,只显示用法和选项 |
-a | 无 | 显示所有的内置命令和关键字 |
-p | 无 | 显示所有的内置命令,不包括关键字 |
Linux help命令的实例
实例1:显示所有的内置命令和关键字
如果不带任何参数,help命令会显示所有的内置命令和关键字,以及它们的简短描述。例如:
[linux@bashcommandnotfound.cn ~]$ help
GNU bash, version 5.1.8(1)-release (x86_64-pc-linux-gnu)
These shell commands are defined internally. Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.
A star (*) next to a name means that the command is disabled.
job_spec [&] history [-c] [-d offset] [n] or hist>
(( expression )) if COMMANDS; then COMMANDS; [ elif C>
. filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
: kill [-s sigspec | -n signum | -sigs>
[ arg... ] let arg [arg ...]
[[ expression ]] local [option] name[=value] ...
alias [-p] [name[=value] ... ] logout [n]
bg [job_spec ...] mapfile [-d delim] [-n count] [-O or>
bind [-lpsvPSVX] [-m keymap] [-f file> popd [-n] [+N | -N]
break [n] printf [-v var] format [arguments]
builtin [shell-builtin [arg ...]] pushd [-n] [+N | -N | dir]
caller [expr] pwd [-LP]
case WORD in [PATTERN [| PATTERN]...)> read [-ers] [-a array] [-d delim] [->
cd [-L|[-P [-e]] [-@]] [dir] readarray [-d delim] [-n count] [-O >
command [-pVv] command [arg ...] readonly [-aAf] [name[=value] ...] o>
compgen [-abcdefgjksuv] [-o option] [> return [n]
complete [-abcdefgjksuv] [-pr] [-DE] > select NAME [in WORDS ... ;] do COMM>
compopt [-o|+o option] [-DE] [name ..> set [-abefhkmnptuvxBCHP] [-o option->
continue [n] shift [n]
coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...]
declare [-aAfFgilnrtux] [-p] [name[=v> source filename [arguments]
dirs [-clpv] [+N] [-N] suspend [-f]
disown [-h] [-ar] [jobspec ... | pid > test [expr]
echo [-neE] [arg ...] time [-p] pipeline
enable [-a] [-dnps] [-f filename] [na> times
eval [arg ...] trap [-lp] [[arg] signal_spec ...]
exec [-cl] [-a name] [command [argume> true
exit [n] type [-afptP] name [name ...]
export [-fn] [name[=value] ...] or ex> typeset [-aAfFgilnrtux] [-p] name[=v>
false ulimit [-SHabcdefiklmnpqrstuvxPT] [l>
fc [-e ename] [-lnr] [first] [last] o> umask [-p] [-S] [mode]
fg [job_spec] unalias [-a] name [name ...]
for NAME [in WORDS ... ] ; do COMMAND> unset [-f] [-v] [-n] [name ...]
for (( exp1; exp2; exp3 )); do COMMAN> until COMMANDS; do COMMANDS; done
function name { COMMANDS ; } or name > variables - Names and meanings of so>
getopts optstring name [arg] wait [-fn] [id ...]
hash [-lr] [-p pathname] [-dt] [name > while COMMANDS; do COMMANDS; done
help [-dms] [pattern ...] { COMMANDS ; }
...
实例2:显示某个内置命令的帮助信息
如果带一个参数,help命令会显示该参数对应的内置命令的帮助信息,包括用法,选项和示例。例如:
[linux@bashcommandnotfound.cn ~]$ help cd
cd: cd [-L|[-P [-e]] [-@]] [dir]
Change the shell working directory.
Change the current directory to DIR. The default DIR is the value of the
HOME shell variable.
The variable CDPATH defines the search path for the directory containing
DIR. Alternative directory names in CDPATH are separated by a colon (:).
A null directory name is the same as the current directory. If DIR begins
with a slash (/), then CDPATH is not used.
If the directory is not found, and the shell option `cdable_vars' is set,
the word is assumed to be a variable name. If that variable has a value,
its value is used for DIR.
Options:
-L force symbolic links to be followed: resolve symbolic
links in DIR after processing instances of `..'
-P use the physical directory structure without following
symbolic links: resolve symbolic links in DIR before
processing instances of `..'
-e if the -P option is supplied, and the current working
directory cannot be determined successfully, exit with
a non-zero status
-@ on systems that support it, present a file with extended
attributes as a directory containing the file attributes
The default is to follow symbolic links, as if `-L' were specified.
`..' is processed by removing the immediately previous pathname component
back to a slash or the beginning of DIR.
Exit Status:
Returns 0 if the directory is changed, and if $PWD is set successfully when
-P is used; non-zero otherwise.
实例3:显示某个内置命令的简短描述
如果带一个参数和-d选项,help命令会显示该参数对应的内置命令的简短描述,不包括用法和选项。例如:
[linux@bashcommandnotfound.cn ~]$ help -d cd
cd: Change the shell working directory.
实例4:显示某个内置命令的帮助信息,使用man风格的格式
如果带一个参数和-m选项,help命令会显示该参数对应的内置命令的帮助信息,使用man风格的格式,包括用法,选项,参数,返回值和示例。例如:
[linux@bashcommandnotfound.cn ~]$ help -m cd
NAME
cd - Change the shell working directory.
SYNOPSIS
cd [-L|[-P [-e]] [-@]] [dir]
DESCRIPTION
Change the current directory to DIR. The default DIR is the value of the
HOME shell variable.
The variable CDPATH defines the search path for the directory containing
DIR. Alternative directory names in CDPATH are separated by a colon (:).
A null directory name is the same as the current directory. If DIR begins
with a slash (/), then CDPATH is not used.
If the directory is not found, and the shell option `cdable_vars' is set,
the word is assumed to be a variable name. If that variable has a value,
its value is used for DIR.
Options:
-L force symbolic links to be followed: resolve symbolic
links in DIR after processing instances of `..'
-P use the physical directory structure without following
symbolic links: resolve symbolic links in DIR before
processing instances of `..'
-e if the -P option is supplied, and the current working
directory cannot be determined successfully, exit with
a non-zero status
-@ on systems that support it, present a file with extended
attributes as a directory containing the file attributes
The default is to follow symbolic links, as if `-L' were specified.
`..' is processed by removing the immediately previous pathname component
back to a slash or the beginning of DIR.
Exit Status:
Returns 0 if the directory is changed, and if $PWD is set successfully when
-P is used; non-zero otherwise.
EXAMPLES
cd
Change the current directory to the value of $HOME.
cd /usr/local/bin
Change the current directory to /usr/local/bin.
cd ..
Change the current directory to the parent directory of the current
directory.
cd -
Change the current directory to the previous directory.
cd ~bob
Change the current directory to the home directory of user bob.
cd $TMPDIR
Change the current directory to the value of the variable TMPDIR.
SEE ALSO
bash(1), pushd(1), popd(1), dirs(1), pwd(1), readlink(1)
实例5:显示某个内置命令的帮助信息,只显示用法和选项
如果带一个参数和-s选项,help命令会显示该参数对应的内置命令的帮助信息,只显示用法和选项,不包括描述和示例。例如:
[linux@bashcommandnotfound.cn ~]$ help -s cd
cd: cd [-L|[-P [-e]] [-@]] [dir]
实例6:显示所有的内置命令,不包括关键字
如果带一个-a选项,help命令会显示所有的内置命令,不包括关键字,以及它们的简短描述。例如:
[linux@bashcommandnotfound.cn ~]$ help -a
GNU bash, version 5.1.8(1)-release (x86_64-pc-linux-gnu)
These shell commands are defined internally. Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.
A star (*) next to a name means that the command is disabled.
alias [-p] [name[=value] ... ] history [-c] [-d offset] [n] or hist>
bg [job_spec ...] jobs [-lnprs] [jobspec ...] or jobs >
bind [-lpsvPSVX] [-m keymap] [-f file> kill [-s sigspec | -n signum | -sigs>
break [n] let arg [arg ...]
builtin [shell-builtin [arg ...]] local [option] name[=value] ...
caller [expr] logout [n]
cd [-L|[-P [-e]] [-@]] [dir] mapfile [-d delim] [-n count] [-O or>
command [-pVv] command [arg ...] popd [-n] [+N | -N]
compgen [-abcdefgjksuv] [-o option] [> printf [-v var] format [arguments]
complete [-abcdefgjksuv] [-pr] [-DE] > pushd [-n] [+N | -N | dir]
compopt [-o|+o option] [-DE] [name ..> pwd [-LP]
continue [n] read [-ers] [-a array] [-d delim] [->
coproc [NAME] command [redirections] readarray [-d delim] [-n count] [-O >
declare [-aAfFgilnrtux] [-p] [name[=v> readonly [-aAf] [name[=value] ...] o>
dirs [-clpv] [+N] [-N] return [n]
disown [-h] [-ar] [jobspec ... | pid > select NAME [in WORDS ... ;] do COMM>
echo [-neE] [arg ...] set [-abefhkmnptuvxBCHP] [-o option->
enable [-a] [-dnps] [-f filename] [na> shift [n]
eval [arg ...] shopt [-pqsu] [-o] [optname ...]
exec [-cl] [-a name] [command [argume> source filename [arguments]
exit [n] suspend [-f]
export [-fn] [name[=value] ...] or ex> test [expr]
false time [-p] pipeline
fc [-e ename] [-lnr] [first] [last] o> times
fg [job_spec] trap [-lp] [[arg] signal_spec ...]
for NAME [in WORDS ... ] ; do COMMAND> true
for (( exp1; exp2; exp3 )); do COMMAN> type [-afptP] name [name ...]
function name { COMMANDS ; } or name > typeset [-aAfFgilnrtux] [-p] name[=v>
getopts optstring name [arg] ulimit [-SHabcdefiklmnpqrstuvxPT] [l>
hash [-lr] [-p pathname] [-dt] [name > umask [-p] [-S] [mode]
help [-dms] [pattern ...] unalias [-a] name [name ...]
if COMMANDS; then COMMANDS; [ elif C> unset [-f] [-v] [-n] [name ...]
jobs [-lnprs] [jobspec ...] or jobs > until COMMANDS; do COMMANDS; done
kill [-s sigspec | -n signum | -sigs> variables - Names and meanings of so>
let arg [arg ...] wait [-fn] [id ...]
local [option] name[=value] ... while COMMANDS; do COMMANDS; done
logout [n] { COMMANDS ; }
实例7:显示所有的内置命令,不包括关键字,只显示用法和选项
如果带一个-p选项,help命令会显示所有的内置命令,不包括关键字,只显示用法和选项,不包括描述和示例。例如:
[linux@bashcommandnotfound.cn ~]$ help -p
alias: alias [-p] [name[=value] ... ]
bg: bg [job_spec ...]
bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
break: break [n]
builtin: builtin [shell-builtin [arg ...]]
caller: caller [expr]
cd: cd [-L|[-P [-e]] [-@]] [dir]
command: command [-pVv] command [arg ...]
compgen: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]
...
Linux help命令的注意事项
- help命令只能显示内置命令的帮助信息,如果要查看其他命令的帮助信息,可以使用man或info命令。
- help命令只能在bash shell中使用,如果你使用的是其他的shell,比如zsh或fish,你可能需要使用其他的命令来查看内置命令的帮助信息,比如zsh的run-help命令或fish的help命令。
- 如果你输入的命令不是一个内置命令,help命令会提示你bash: help: no help topics match
xxx'. Try
help help' orman -k xxx' or
info xxx'.,表示没有找到匹配的帮助主题,建议你使用help help或man -k xxx或info xxx来查找相关的帮助信息。
评论区