Bash’s default editing mode is Emacs. Here’s a list of the most useful shortcuts to help you navigate and edit the command line efficiently.
Cursor Movement
Command
Description
C-a
Move to the beginning of the line
C-e
Move to the end of the line
C-b
Move backward one character
C-f
Move forward one character
M-b
Move backward one word
M-f
Move forward one word
C-l
Clear screen and redisplay the line
Editing Text
Command
Description
C-d
Delete the character under the cursor
C-h
Delete the character before the cursor
M-d
Delete the word after the cursor
M-DEL
Delete the word before the cursor
C-k
Kill from cursor to end of line
C-u
Kill from cursor to beginning of line
C-w
Kill the word behind the cursor
M-t
Transpose (swap) the last two words
C-t
Transpose (swap) the last two characters
C-y
Yank (paste) the last killed text
Command History
Command
Description
C-p
Previous command in history
C-n
Next command in history
M-<
Move to the first command in history
M->
Move to the last command in history
C-r
Reverse search through history
C-s
Forward search through history (might be disabled in some terminals)
Miscellaneous
Command
Description
C-_ or C-x C-u
Undo the last editing command
C-x C-e
Edit the current line in an external editor (usually vi or emacs)
M-&
Run the previous command in the background
C-v or M-v
Insert the next character typed literally (e.g., allows input of control characters)
Note: In this cheat sheet, C stands for the Control key and M stands for the Meta key (usually the Alt or Option key). Combining C or M with a character means pressing the Control or Meta key, respectively, while also pressing that character.
** If you want to check what else I'm currently doing, be sure to follow me on twitter @rderik or subscribe to the newsletter. If you want to send me a direct message, you can send it to derik@rderik.com.