Nathan Hoad

Useful Bash shortcuts

March 2, 2012

I’m a bit of an efficiency freak, and I like being comfortable and working without hassle. Lately, I’ve been working on learning Bash keyboard shortcuts to make using the terminal as easy as possible. Here is the list of shortcuts that I’ve grown to almost use every day:


Ctrl-aMove to the start of the line
Ctrl-eMove to the end of the line
Ctrl-bMove back one character
Alt-bMove back one word
Ctrl-fMove forward one character
Alt-fMove forward one word
Ctrl-] xMove the cursor forward to next occurance of x
Alt-Ctrl-] x Move the cursor backward to the next occurance of x 

Line Modification

Ctrl-uDelete from the cursor to the beginning of the line 
Ctrl-kDelete from the cursor to the end of the line 
Esc BackspaceDelete back a word
Alt-dDelete forward a word
Alt-rUndo all changes to the line
Ctrl-yPaste any text deleted with previous shortcuts 
Ctrl-e Esc-tSwap order of the last two arguments

History Utilisation

Ctrl-x Ctrl-uUndo the last change to the line
Ctrl-rIncremental reverse search of history
Alt-pNon-incremental reverse search of history
Ctrl-LClear the screen (doesn't wipe current line)
!!Execute last command in history
!abcExecute last command in history beginning with abc
!nExecute nth command in history
!$Last argument of previous command
!^First argument of previous command
^abc^xyzReplace first occurance of abc with xyz in previous command and execute it
Alt-. (period)Paste last word from previous command after cursor position (repeat to cycle through previous commands)

Enjoy! Particularly useful are Ctrl-r, Alt-., and any command involving movement.