讓你提高命令行效率的 Bash 快捷鍵

http://linuxtoy.org/archives/bash-shortcuts.html

讓你提高命令行效率的 Bash 快捷鍵 [完整版]

生活在 Bash shell 中,熟記如下快捷鍵,將極大的提升你的 命令行操做效率。

編輯命令

  • Ctrl + a :移到命令行首
  • Ctrl + e :移到命令行尾
  • Ctrl + f :按字符前移(右向)
  • Ctrl + b :按字符後移(左向)
  • Alt + f :按單詞前移(右向)
  • Alt + b :按單詞後移(左向)
  • Ctrl + xx:在命令行首和光標之間移動
  • Ctrl + u :從光標處刪除至命令行首
  • Ctrl + k :從光標處刪除至命令行尾
  • Ctrl + w :從光標處刪除至字首
  • Alt + d :從光標處刪除至字尾
  • Ctrl + d :刪除光標處的字符
  • Ctrl + h :刪除光標前的字符
  • Ctrl + y :粘貼至光標後
  • Alt + c :從光標處更改成首字母大寫的單詞
  • Alt + u :從光標處更改成所有大寫的單詞
  • Alt + l :從光標處更改成所有小寫的單詞
  • Ctrl + t :交換光標處和以前的字符
  • Alt + t :交換光標處和以前的單詞
  • Alt + Backspace:與 Ctrl + w 相同相似,分隔符有些差異 [感謝 rezilla 指正]

從新執行命令

  • Ctrl + r:逆向搜索命令歷史
  • Ctrl + g:從歷史搜索模式退出
  • Ctrl + p:歷史中的上一條命令
  • Ctrl + n:歷史中的下一條命令
  • Alt + .:使用上一條命令的最後一個參數

控制命令

  • Ctrl + l:清屏
  • Ctrl + o:執行當前命令,並選擇上一條命令
  • Ctrl + s:阻止屏幕輸出
  • Ctrl + q:容許屏幕輸出
  • Ctrl + c:終止命令
  • Ctrl + z:掛起命令

Bang (!) 命令

  • !!:執行上一條命令
  • !blah:執行最近的以 blah 開頭的命令,如 !ls
  • !blah:p:僅打印輸出,而不執行
  • !$:上一條命令的最後一個參數,與 Alt + . 相同
  • !$:p:打印輸出 !$ 的內容
  • !*:上一條命令的全部參數
  • !*:p:打印輸出 !* 的內容
  • ^blah:刪除上一條命令中的 blah
  • ^blah^foo:將上一條命令中的 blah 替換爲 foo
  • ^blah^foo^:將上一條命令中全部的 blah 都替換爲 foo
友情提示
  1. 以上介紹的大多數 Bash 快捷鍵僅當在 emacs 編輯模式時有效,若你將 Bash 配置爲 vi 編輯模式,那將遵循 vi 的按鍵綁定。Bash 默認爲 emacs 編輯模式。若是你的 Bash 不在 emacs 編輯模式,可經過 set -o emacs 設置。
  2. ^S、^Q、^C、^Z 是由終端設備處理的,可用 stty 命令設置。
{ via }
Read More:

26 Comments

  1. 1 gDD Commented @ 2011-11-13 11:56Reply
    強大啊,爲了活得更滋潤點,決定都背下來。。。
  2. 2 康上明學 Commented @ 2011-11-13 11:56Reply
    知道一些經常使用的,這裏面大部分齊全了。
  3. 3 adam8157 Commented @ 2011-11-13 12:00Reply
    Nice
  4. 4 yjc Commented @ 2011-11-13 12:07Reply
    好多和emacs 命令同樣
  5. 5 kevin Commented @ 2011-11-13 12:08Reply
    不錯不錯,樓主好人,樓主一輩子平安
  6. 6 gDD Commented @ 2011-11-13 12:19Reply
    還能夠看看這裏,快捷鍵部分說得更詳細:
  7. 7 rezilla Commented @ 2011-11-13 12:31Reply
    alt-backspace 和 ctrl-w不徹底相同,分隔符有些差異
  8. 8 mikeandmore Commented @ 2011-11-13 12:56Reply
    rmbus會在這篇留言麼?
  9. 9 nanashi Commented @ 2011-11-13 12:57Reply
    之前不知道Ctrl + s,誤按後不得不重開...
  10. 10 arnkore Commented @ 2011-11-13 13:35Reply
    emacs用戶表示毫無壓力。
  11. 11 pityonline Commented @ 2011-11-13 13:46Reply
    Alt+f,Alt+b,Alt+t 和 gnome-terminal 的菜單快捷鍵有衝突……
  12. 12 thynson Commented @ 2011-11-13 14:07Reply
    在. bashrc裏面加上set -o vi,大家懂的
  13. 13 transtone Commented @ 2011-11-13 14:17Reply
    惋惜至關一部分對zsh無效。 bash的complete功能仍是有點弱。
  14. 14 dreamersdw Commented @ 2011-11-13 14:21Reply
    bash: bind -P zsh: bindkey
    就這些了
  15. 15 自由建客 Commented @ 2011-11-13 16:12Reply
    set -o vi 沒有壓力
  16. 16 rmbus Commented @ 2011-11-13 17:19Reply
    stupid tips~!
  17. 17 chatbot Commented @ 2011-11-13 19:43Reply
    man bash, 查看READLINE和HISTORY EXPANSION兩個章節會對本文內容有更全面的瞭解。快捷鍵的設置對應 bash中的bind內置 命令,相關內容能夠man bash以後/^\s*bind [查看
  18. 18 monkeymonk Commented @ 2011-11-13 19:48Reply
    @ pityonline: 通常我要編輯的話,先把菜單欄隱藏「Ctrl + H」.
  19. 19 mikeandmore Commented @ 2011-11-14 1:02Reply
    看到rmbus可是沒有看到rmbus噴 bash……好失落………………
  20. 20 hshqcn Commented @ 2011-11-14 11:10Reply
    給力,以及樓上各位。 從reader趕來頂貼,必須的!
  21. 21 Billy Commented @ 2011-11-15 8:38Reply
    從reader趕來,強帖,用了好久的大便,對這些 命令只知道其中幾個
  22. 22 hckjsnzf Commented @ 2011-11-15 16:27Reply
    不錯,不錯。
  23. 23 zhichyu Commented @ 2011-11-16 9:20Reply
    @ monkeymonk: 你這一招在ubuntu 11.10上不湊效啊。
  24. 24 vinoca Commented @ 2011-11-16 13:47Reply
    用zsh,emacs鍵綁定是通用的。支持!
  25. 25 清風博客 Commented @ 2011-11-16 15:01Reply
    Emacser 表示毫無壓力。
  26. 26 whenov Commented @ 2011-11-17 21:44Reply
    請問爲何^blah^foo^只能替換上一條 命令的第一個blah?
相關文章
相關標籤/搜索