北京赛车pk10直播开奖
首頁
登錄 | 注冊

獲取有關 Linux shell 內置命令的幫助

Linux 內置命令屬于用戶 shell 的一部分,本文將告訴你如何識別它們并獲取使用它們的幫助。

Linux 內置命令是內置于 shell 中的命令,很像內置于墻中的書架。與標準 Linux 命令存儲在 /usr/bin 中的方式不同,你不會找到它們的獨立文件,你可能使用過相當多的內置命令,但你不會感覺到它們與 ls 和 pwd 等命令有何不同。

內置命令與其他 Linux 命令一樣使用,它們可能要比不屬于 shell 的類似命令運行得快一些。Bash 內置命令包括 alias、export 和 bg 等。

正如你擔心的那樣,因為內置命令是特定于 shell 的,所以它們不會提供手冊頁。使用 man 來查看 bg,你會看到這樣的東西:

  1. $ man bg
  2. No manual entry for bg

判斷內置命令的另一個提示是當你使用 which 命令來識別命令的來源時,Bash 不會響應,表示沒有與內置命令關聯的文件:

  1. $ which bg
  2. $

另一方面,如果你的 shell 是 /bin/zsh,你可能會得到一個更有啟發性的響應:

  1. % which bg
  2. bg: shell built-in command

bash 提供了額外的幫助信息,但它是通過使用 help 命令實現的:

  1. $ help bg
  2. bg: bg [job_spec ...]
  3. Move jobs to the background.
  4. Place the jobs identified by each JOB_SPEC in the background,asif they
  5. had been started with`&'. If JOB_SPEC is not present, the shell's notion
  6. of the current job is used.
  7. Exit Status:
  8. Returns success unless job control is not enabled or an error occurs.

如果你想要查看 bash 提供的所有內置命令的列表,使用 compgen -b 命令。通過管道將命令輸出到列中,以獲得較好格式的清單。

  1. $ compgen -b | column
  2. . compgen exit let return typeset
  3. : complete exportlocalset ulimit
  4. [ compopt false logout shift umask
  5. aliascontinue fc mapfile shopt unalias
  6. bg declare fg popd source unset
  7. bind dirs getopts printf suspend wait
  8. break disown hash pushd test
  9. builtin echo help pwd times
  10. caller enable history read trap
  11. cdeval jobs readarray true
  12. command execkill readonly type

如果你使用 help 命令,你將看到一個內置命令列表以及簡短描述。但是,這個列表被截斷了(以 help 命令結尾):

  1. $ help
  2. GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
  3. These shell commands are defined internally.Type`help' to see this list.
  4. Type `help name' to find out more about the function `name'.
  5. Use`info bash' to find out more about the shell in general.
  6. Use `man-k' or `info' to find out more about commands notinthislist.
  7. A star (*)next to a name means that the command is disabled.
  8. job_spec [&] history [-c][-d offset][n]or histo>
  9. (( expression ))if COMMANDS;then COMMANDS;[elif CO>
  10. . filename [arguments] jobs [-lnprs][jobspec ...]or jobs ->
  11. :kill[-s sigspec |-n signum |-sigsp>
  12. [ arg...] let arg [arg ...]
  13. [[ expression ]]local[option] name[=value]...
  14. alias[-p][name[=value]...] logout [n]
  15. bg [job_spec ...] mapfile [-d delim][-n count][-O ori>
  16. bind [-lpsvPSVX][-m keymap][-f filen> popd [-n][+N |-N]
  17. break[n]printf[-v var] format [arguments]
  18. builtin [shell-builtin [arg ...]] pushd [-n][+N |-N |dir]
  19. caller[expr]pwd[-LP]
  20. case WORD in[PATTERN [| PATTERN]...)> read [-ers][-a array][-d delim][-i>
  21. cd[-L|[-P [-e]][[email protected]]][dir] readarray [-d delim][-n count][-O o>
  22. command [-pVv] command [arg ...] readonly [-aAf][name[=value]...]or>
  23. compgen [-abcdefgjksuv][-o option][->return[n]
  24. complete [-abcdefgjksuv][-pr][-DEI]> select NAME [in WORDS ...;]do COMMA>
  25. compopt [-o|+o option][-DEI][name ..>set[-abefhkmnptuvxBCHP][-o option-n>
  26. continue[n] shift [n]
  27. coproc [NAME] command [redirections] shopt [-pqsu][-o][optname ...]
  28. declare[-aAfFgilnrtux][-p][name[=va> source filename [arguments]
  29. dirs [-clpv][+N][-N] suspend [-f]
  30. disown [-h][-ar][jobspec ...| pid .<p&gt'> test [expr]
  31. echo [-neE] [arg ...] time [-p] pipeline
  32. enable [-a] [-dnps] [-f filename] [nam> times
  33. eval [arg ...] trap [-lp] [[arg] signal_spec ...]
  34. exec [-cl] [-a name] [command [argumen> true
  35. exit [n] type [-afptP] name [name ...]
  36. export [-fn] [name[=value] ...] or exp> typeset [-aAfFgilnrtux] [-p] name[=va>
  37. false ulimit [-SHabcdefiklmnpqrstuvxPT] [li>
  38. fc [-e ename] [-lnr] [first] [last] or> umask [-p] [-S] [mode]
  39. fg [job_spec] unalias [-a] name [name ...]
  40. for NAME [in WORDS ... ] ; do COMMANDS> unset [-f] [-v] [-n] [name ...]
  41. for (( exp1; exp2; exp3 )); do COMMAND> until COMMANDS; do COMMANDS; done
  42. function name { COMMANDS ; } or name (> variables - Names and meanings of som>
  43. getopts optstring name [arg] wait [-fn] [id ...]
  44. hash [-lr] [-p pathname] [-dt] [name .> while COMMANDS; do COMMANDS; done
  45. help [-dms] [pattern ...] { COMMANDS ; }

從上面的清單中可以看出,help 命令本身就是內置的。

你可以通過向 help 命令提供你感興趣的內置命令名稱來獲取關于它們的更多信息,例如 help dirs:

  1. $ help dirs
  2. dirs: dirs [-clpv][+N][-N]
  3. Display directory stack.
  4. Display the list of currently remembered directories.Directories
  5. find their way onto the listwith the `pushd' command; you can get
  6. back up through the list with the `popd' command.
  7. Options:
  8. -c clear the directory stack by deleting all of the elements
  9. -l do not print tilde-prefixed versions of directories relative
  10. to your home directory
  11. -p print the directory stack with one entry per line
  12. -v print the directory stack with one entry per line prefixed
  13. with its position in the stack
  14. Arguments:
  15. +N Displays the Nth entry counting from the left of the list
  16. shown by dirs when invoked without options, starting with
  17. zero.
  18. -N Displays the Nth entry counting from the right of the list
  19. shown by dirs when invoked without options, starting with
  20. zero.
  21. Exit Status:
  22. Returns success unless an invalid option is supplied or an error occurs.

內置命令提供了每個 shell 的大部分功能。你使用的任何 shell 都有一些內置命令,但是如何獲取這些內置命令的信息可能因 shell 而異。例如,對于 zsh,你可以使用 man zshbuiltins 命令獲得其內置命令的描述。

  1. $ man zshbuiltins
  2. ZSHBUILTINS(1)GeneralCommandsManual ZSHBUILTINS(1)
  3. NAME
  4. zshbuiltins - zsh built-in commands
  5. SHELL BUILTIN COMMANDS
  6. Some shell builtin commands take options as described in individual en‐
  7. tries; these are often referred to in the list below as`flags' to avoid
  8. confusion with shell options, which may also have an effect on the behav‐
  9. iour of builtin commands. In this introductory section, `option' always
  10. has the meaning of an option to a command that should be familiar to most
  11. command line users.

在這個冗長的手冊頁中,你將找到一個內置命令列表,其中包含有用的描述,如下摘錄中所示:

  1. bg [ job ...]
  2. job ...&
  3. Put each specified job in the background,or the current job if
  4. none is specified.
  5. bindkey
  6. See the section `Zle Builtins' in zshzle(1).
  7. break [ n ]
  8. Exit from an enclosing for, while, until, select or repeat loop.
  9. If an arithmetic expression n is specified, then break n levels
  10. instead of just one.

最后

Linux 內置命令對于每個 shell 都很重要,它的操作類似特定于 shell 的命令一樣。如果你經常使用不同的 shell,并注意到你經常使用的某些命令似乎不存在或者不能按預期工作,那么它可能是你使用的其他 shell 之一中的內置命令。

via:networkworld



2019 monjeep.com webmaster#monjeep.com
12 q. 0.009 s.
京ICP備10005923號
北京赛车pk10直播开奖
二分彩计划有什么规律 大赢家足球即时比分蠃 辽宁十一选五预测 下载二人斗地主 免费北京麻将游戏 113彩票注册 北京单场app 建足球场 斗牛怎么玩法算法 网络棋牌炸金花规律