Shortcuts for Bash
by Tullio Facchinetti
Typically, we use arrow keys to control shell behaviors like moving the cursor from one point to another point. Also, it’s quite common to make mistakes while writing commands and to correct these you may use arrow keys + backspace, which is not optimal at all.
In the bash terminal, you can use several keystrokes to control the shell features that you are going to see.
Shortcuts to move cursor
The first thing you should know is how to move the cursor using the list of keystrokes that you can use to move around the shells.
Ctrl + A
: directly jump to the start of the command lineCtrl + E
: move to the end of the lineCtrl + B
: move cursor to the leftCtrl + F
: move cursor to the rightAlt + B
: jump to the left wordAlt + F
: jump to the right wordCtrl + left arrow
: jump to left word (similar toAlt + B
)Ctrl + right arrow
: jump to right word (similar toAlt + F
)
Shortcuts to manipulate text
Does it make your work easier? Of course, yes. Now you will see more keystrokes that can manipulate text.
Ctrl + U
: erase or cut the whole lineCtrl + K
: erase or cut the line after the cursor positionsCtrl + Y
: paste word or text that has cutCtrl + D
: delete character under the cursorCtrl + H
: delete character under the cursor including backspaceCtrl + W
: delete words before the cursorCtrl + Backspace
: delete words before the cursor (similar toCtrl + W
)Ctrl + T
: swap character with a last characterEsc + T
: swap last two wordsAlt + U
: change lowercase to UPPERCASE to end of cusorAlt + I
: change UPPERCASE to lowercase character to end of cursorAlt + C
: make an uppercase character which is under cursorAlt + D
: delete word or character next to cursor
Common shortcuts
Some of the common keystrokes that you can use while working on the terminal are listed below.
Ctrl + P
: go backward through your previous invoked commandCtrl + N
: go forward through your invoked commandCtrl + R
: search command from historyCtrl + L
: clear the screenCtrl + S
: suspend command outputCtrl + Q
: resume command outputCtrl + Z
: stop commandCtrl + C
: Exit command
The following are not strictly shortcuts, but commands that require an ENTER to be executed:
!!
: run last executed command
Credits
This list comes from this post. I replicated it here since I often have problems accessing the original post.