網頁

搜尋此網誌

2012年2月22日 星期三

Bash Builtin Commands 內建指令

Linux啟動之後所進入的通常就是Bash,面對這個Command-line Interface我們使用者應該如何操作!黑黑的畫面上閃爍著輸入游標,到底有什麼指令可以使用?請求協助輸入help是一個方法,但這只會列出Bash內建的所有指令

列出Bash內建的所有指令與敘述:help -d '*'
  1. % - Resume job in foreground.
  2. (( ... )) - Evaluate arithmetic expression.
  3. . - Execute commands from a file in the current shell.
  4. : - Null command.
  5. [ - Evaluate conditional expression.
  6. [[ ... ]] - Execute conditional command.
  7. alias - Define or display aliases.
  8. bg - Move jobs to the background.
  9. bind - Set Readline key bindings and variables.
  10. break - Exit for, while, or until loops.
  11. builtin - Execute shell builtins.
  12. caller - Return the context of the current subroutine call.
  13. case - Execute commands based on pattern matching.
  14. cd - Change the shell working directory.
  15. command - Execute a simple command or display information about commands.
  16. compgen - Display possible completions depending on the options.
  17. complete - Specify how arguments are to be completed by Readline.
  18. compopt - Modify or display completion options.
  19. continue - Resume for, while, or until loops.
  20. coproc - Create a coprocess named NAME.
  21. declare - Set variable values and attributes.
  22. dirs - Display directory stack.
  23. disown - Remove jobs from current shell.
  24. echo - Write arguments to the standard output.
  25. enable - Enable and disable shell builtins.
  26. eval - Execute arguments as a shell command.
  27. exec - Replace the shell with the given command.
  28. exit - Exit the shell.
  29. export - Set export attribute for shell variables.
  30. false - Return an unsuccessful result.
  31. fc - Display or execute commands from the history list.
  32. fg - Move job to the foreground.
  33. for - Execute commands for each member in a list.
  34. for (( - Arithmetic for loop.
  35. function - Define shell function.
  36. getopts - Parse option arguments.
  37. hash - Remember or display program locations.
  38. help - Display information about builtin commands.
  39. history - Display or manipulate the history list.
  40. if - Execute commands based on conditional.
  41. jobs - Display status of jobs.
  42. kill - Send a signal to a job.
  43. let - Evaluate arithmetic expressions.
  44. local - Define local variables.
  45. logout - Exit a login shell.
  46. mapfile - Read lines from the standard input into an indexed array variable.
  47. popd - Remove directories from stack.
  48. printf - Formats and prints ARGUMENTS under control of the FORMAT.
  49. pushd - Add directories to stack.
  50. pwd - Print the name of the current working directory.
  51. read - Read a line from the standard input and split it into fields.
  52. readarray - Read lines from a file into an array variable.
  53. readonly - Mark shell variables as unchangeable.
  54. return - Return from a shell function.
  55. select - Select words from a list and execute commands.
  56. set - Set or unset values of shell options and positional parameters.
  57. shift - Shift positional parameters.
  58. shopt - Set and unset shell options.
  59. source - Execute commands from a file in the current shell.
  60. suspend - Suspend shell execution.
  61. test - Evaluate conditional expression.
  62. time - Report time consumed by pipeline's execution.
  63. times - Display process times.
  64. trap - Trap signals and other events.
  65. true - Return a successful result.
  66. type - Display information about command type.
  67. typeset - Set variable values and attributes.
  68. ulimit - Modify shell resource limits.
  69. umask - Display or set file mode mask.
  70. unalias - Remove each NAME from the list of defined aliases.
  71. unset - Unset values and attributes of shell variables and functions.
  72. until - Execute commands as long as a test does not succeed.
  73. variables - Common shell variable names and usage.
  74. wait - Wait for job completion and return exit status.
  75. while - Execute commands as long as a test succeeds.
  76. { ... } - Group commands as a unit.
可以看到Bash內建的指令大概有70多個,至於Linux上全部的指令可以參考O'Reilly的Linux Command Directory

心得感想:對於任何電腦系統,務必熟悉最重要的help指令,不知道怎麼操作就請「help」吧,但前提是你要知道有「help」啊!

相關指令:
  • 確認shell的種類:echo $SHELL
  • 顯示Bash的版本:echo $BASH_VERSION

###

Linux Basic vbird 鳥哥的私房菜

只要學習Linux的人,應該都知道「鳥哥的Linux私房菜」網站與書籍,鳥哥撰寫的文章對於自學者非常有幫助,可以讓不懂Linux的人循序上手,當然,如果身旁有老師或高手更好,避免「鳥哥的Linux苦難經驗」重蹈覆轍在自己身上,更感謝鳥哥免費分享他的學習之路與經驗。

最近真正深入Linux領域,趁著博客來特價優惠,趕緊將兩本「鳥哥的Linux私房菜」買下手,一本是基礎學習篇,另一本是伺服器架設篇,目前已經都是第三版,雖然說書的內容與網站上沒有差異,然而還是閱讀書籍比較舒適,建議想學習Linux的人都踴躍支持購買!

蔡德明(鳥哥),鳥哥的Linux私房菜‧基礎學習篇(第三版),台北:碁峰資訊,2010。

整本書分成五篇,共27章(包含第0章的計算機概論),我認為這五大篇也就是學習Linux的五個重點,其中第3篇的操作Bash與Vim算是使用Linux的基本能力,務必要學習且熟悉!
  1. Linux的規劃與安裝
  2. Linux檔案、目錄與磁碟格式
  3. 學習Shell與Shell Scripts
  4. Linux使用者管理
  5. Linux系統管理員
從目前學習Linux的經驗來看,自己大概要花3個月左右才有感覺上手,急不得也不能急,看書與操作Linux的時間大概是一半一半,若是有專家教導應該可以加速學習速度,當然,每天都用Linux的話學習會更快。

由於自己是從Windows轉過來學習Linux,每天開機還是面對Windows,一開始還真是摸不著Linux。建議想想自己在Windows的操作要如何在Linux上面實現,例如複製檔案要怎麼用Bash完成、如何用Vim修改設定檔...之類的使用案例,這種方式學習起來會比較有感覺喔!

###

熱門文章