You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The bash shell uses a library called GNU Readline that provides easy and
quick CLI key combination access to bash history, screen movement and line
editing commands. I've collected some of these here along with some builtin
bash shortcuts for history and other functions.
Note: The command bind -p will list all the keybindings and the readline
functions they call.
Cursor Movement
command
description
ctl + a
Goto beginning of command line
ctl + e
Goto end of command line
ctl + b
Move back one character
ctl + f
Move forward one character
alt + f
Move cursor forward one word
alt + b
Move cursor back one word
ctl + l
Clear the screen (same as clear command)
ctl + ] <char>
Move forward to next occurrence of <char>
alt + ctrl + [ <char>
Move backwards to previous occurrence of <char>
Line editing
command
description
alt + .
Print the last argument (ie "vim file1.txt file2.txt" will yield "file2.txt")
esc + t
Swap last two words before the cursor
ctl + d
Delete the character under the cursor
ctl + h
Delete character before the cursor
ctl + u
Delete everything before cursor
ctl + k
Delete everything after cursor
alt + backspace
Delete previous word
ctl + w
Delete the word before the cursor
ctl + t
Swap the last two characters before the cursor
ctl + y
Paste (if you used a previous command to delete)
ctl + z
Place current process in background
ctl + _
Undo
ctl + x + ctl + e
Open current line in $EDITOR
History
command
description
!!
Run previous command (e.g. sudo !!)
!cmd
Run previous command that begins with cmd
!cmd:p
Print last command in history beginning with cmd
!n
Execute nth command in history
!$
Last argument of last command
!^
First argument of last command
alt + <
Move to the first line in the history
alt + >
Move to the end of the input history, i.e., the current line
ctl + r
Search backward starting at the current line and moving 'up' through the history as necessary
crl + s
Search forward starting at the current line and moving 'down' through the history as necessary
ctl + p
Fetch the previous command from the history list, moving back in the list (same as up arrow)
ctl + n
Fetch the next command from the history list, moving forward in the list (same as down arrow)