Press "Enter" to skip to content

Keyboard shortcuts for BASH

Nothing to earth shaking here, below are all the keyboard shortcuts for the BASH shell that I can think of.. I know there are more and you can customize them to fit.

One note, if you habitually use ‘screen’ Ctrl-a will not move the cursor to the line start, instead it follows the default keymapping for screen and will await the command to change screens.

Moving around

Ctrl-b Move the cursor one character ⇦ to the left
Ctrl-f Move the cursor one character ⇨ to the right
Alt-b Move the cursor one word ⇦ to the left
Alt-f Move the cursor one word ⇨ to the right
Ctrl-a Move the cursor ⇤ to the start of the line
Ctrl-e Move the cursor ⇥ to the end of the line
Ctrl-x-x Move the cursor ⇤⇥ to the start, and to the end again

Cut, copy and paste

Backspace Delete the character ⇦ to the left of the cursor
DEL/Ctrl-d Delete the character underneath the cursor
Ctrl-u Delete everything ⇤ from the cursor back to the line start
Ctrl-k Delete everything ⇥ from the cursor to the end of the line
Alt-d Delete word ⇨ untill before the next word boundary
Ctrl –w Delete word ⇦ untill after the previous word boundary
Ctrl-y Yank/Paste prev. killed text at the cursor position
Alt-y Yank/Paste prev. prev. killed text at the cursor position

History
Ctrl-p Move in history one line up before this line
Ctrl-n Move in history one line down after this line
A-> Move in history all the lines down to the line being eneterd
Ctrl-r Incrementally search the line in history backward
Ctrl-s Incrementally search the line in history forward
Ctrl-j End incremental search
Ctrl-g Abort incremental search AND restore the original line
Alt-Ctrl-y Yank/Paste arg.1 of prev. command at the cursor position
Alt-. / Alt-, Yank/Paste last arg. Of prev. command at the cursor position

Undo
Ctrl-_/Ctrl-x/Ctrl-u Undo the last editing command
Alt-r undo all changes made to this line
Ctrl-l Clear the screen

Completion
TAB Auto-complete a name
Alt-/ Auto-complete a name (without smart completion)
Alt-? /TAB-TAB List the possible completion of the preceding text
Alt-* Insert all possible completions of the preceding text

Transpose (Twiddle)
Ctrl-t Transpose char. Before cursor with the character at the cursor
Alt-t Transpose word before the cursor with the word at the cursor

Ctrl-d Exit the current shell
Ctrl-z Puts whatever you are running into a suspended background process.