Useful Bash shortcuts

filed under bash and linux

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:


Shortcut Action
Ctrl-a Move to the start of the line
Ctrl-e Move to the end of the line
Ctrl-b Move back one character
Alt-b Move back one word
Ctrl-f Move forward one character
Alt-f Move forward one word
Ctrl-] x Move the cursor forward to next occurance of x
Alt-Ctrl-] x  Move the cursor backward to the next occurance of x 

Line Modification

Shortcut Action
Ctrl-u Delete from the cursor to the beginning of the line 
Ctrl-k Delete from the cursor to the end of the line 
Esc Backspace Delete back a word
Alt-d Delete forward a word
Alt-r Undo all changes to the line
Ctrl-y Paste any text deleted with previous shortcuts 
Ctrl-e Esc-t Swap order of the last two arguments

History Utilisation

Shortcut Action
Ctrl-x Ctrl-u Undo the last change to the line
Ctrl-r Incremental reverse search of history
Alt-p Non-incremental reverse search of history
Ctrl-L Clear the screen (doesn't wipe current line)
!! Execute last command in history
!abc Execute last command in history beginning with abc
!n Execute nth command in history
!$ Last argument of previous command
!^ First argument of previous command
^abc^xyz Replace 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.

Related Posts