Pages

Wednesday, January 02, 2008

Bash keyboard shortcut

Below is list of keyboard shortcut for bash shell.

Why we need keyboard shortcut? The short answer is: to save time!
Especially, when we are accessing bash remotely (eg: by ssh) and the network access pretty slow, we will need a keyboard shortcut such as deleting the entire command line, moving to the beginning of the command, etc to save a lot of time.

Below are some of keyboard shortcuts for bash. Maybe in certain conditions it does not work properly.

  • ALT + b : move the cursor backward one word.

  • ALT + f : move the cursor forward one word.

  • ALT + d : cut one word after the cursor.

  • ALT + u : uppercase one word after the cursor.

  • CTRL + a : go to the first character of the line.

  • CTRL + b : move back one character.

  • CTRL + c : Sending signal SIGINT the current process you run (usually the process will be killed).

  • CTRL + d : Sending EOF, Exit/logout the current shell.

  • CTRL + e : go to the last character of the line.

  • CTRL + f : move forward one character.

  • CTRL + h : clear one character before the cursor. (similar with backspace)

  • CTRL + k : cut all characters after the cursor.

  • CTRL + l : clear screen.

  • CTRL + r : search for previously used commands.

  • CTRL + t : swap the last two characters before the cursor.

  • CTRL + u : cut all characters before the cursor.

  • CTRL + w : delete one word before the cursor.

  • CTRL + y : recall the last cut character by CTRL+u or CTRL+k or ALT+d (just like paste)

  • CTRL + z : put the current process you run into background process. To restore it, use command fg.

  • ESC + t : swap the last two words before the cursor.

  • TAB : autocomplete command/files or folders name.


That's all :)

7 comments:

  1. Totally geeking out over this post, thanks.

    Also:

    ESC-l lowercases one word in front of the cursor.

    ReplyDelete
  2. Oh, crap, also-also:

    Esc-f and Esc-b work the same as Alt-f/b, for those of us on OS X who can't use Alt.


    And, no joke, my word verification right now was "codiest".

    ReplyDelete
  3. :D Thanks for the additional shortcut for OS X

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. I guess all of the Alt- shortcuts will work for Esc- also, since the bash manual describes them as only Meta- shortcuts. Meta usually applies to both Alt and Esc keys.

    ReplyDelete
  6. I learned from ping man page thet "Alt + |" (that's pipe) sends SIGQUIT.

    It makes ping print out statistics, there might be other programs handling it.

    ReplyDelete