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 line
Ctrl + E: move to the end of the line
Ctrl + B: move cursor to the left
Ctrl + F: move cursor to the right
Alt + B: jump to the left word
Alt + F: jump to the right word
Ctrl + left arrow: jump to left word (similar to
Alt + B)
Ctrl + right arrow: jump to right word (similar to
Alt + 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 line
Ctrl + K: erase or cut the line after the cursor positions
Ctrl + Y: paste word or text that has cut
Ctrl + D: delete character under the cursor
Ctrl + H: delete character under the cursor including backspace
Ctrl + W: delete words before the cursor
Ctrl + Backspace: delete words before the cursor (similar to
Ctrl + W)
Ctrl + T: swap character with a last character
Esc + T: swap last two words
Alt + U: change lowercase to UPPERCASE to end of cusor
Alt + I: change UPPERCASE to lowercase character to end of cursor
Alt + C: make an uppercase character which is under cursor
Alt + D: delete word or character next to cursor
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 command
Ctrl + N: go forward through your invoked command
Ctrl + R: search command from history
Ctrl + L: clear the screen
Ctrl + S: suspend command output
Ctrl + Q: resume command output
Ctrl + Z: stop command
Ctrl + C: Exit command
The following are not strictly shortcuts, but commands that require an ENTER to be executed:
!!: run last executed command
This list comes from this post. I replicated it here since I often have problems accessing the original post.