As developers, we use the terminal all the time, it makes sense to learn some shortcuts that can help you do things in the command line.
Learning these will also help you boost your productivity because you don't have to retype your commands again just because you found a mistake.
I've also created a short(ish) video that shows some of the shortcuts mentioned in this article.
Note: When I recorded this video, I thought the shortcut
CTRL+U
was deleting the line, but it's just cutting the whole line, you can paste the text withCTRL+Y
.
Shortcuts for moving around
Let's be honest how many times do we write a command, just to notice that around the beginning of the line there is a mistake and we delete everything and type the command again? These shortcuts will help you move the cursor easier without the need to delete the whole thing.
CTRL + A
- Moves the cursor to the beginning of the lineCTRL + E
- Moves the cursor to the end of the lineCTRL + arrow keys
- Moves the cursor from word to wordALT + B
- Moves the cursor back from word to wordALT + F
- Moves cursors forward from word to word
Cutting and pasting
CTRL + W
- Cut the word left of the cursorCTRL + K
- Cut the entire text at the right of the cursorALT + W
- Cut the entire text at the left of the cursorCTRL + U
- Cut the entire lineCTRL + Y
- Paste the previous cut text
Text manipulation
CTRL + T
- Swap two letters between the cursor- Example:
this
if the cursor is between the h and i it turns intotihs
- Example:
ESC + T
- Swap two words between the cursor- Example:
this text
will becometext this
- Example:
ESC + U
- Uppercases text right of the cursor - moves cursor to the end of wordCTRL + Q
- Deletes text from line - clears line only
Other useful shortcuts
CTRL + L
- Clears the terminal -> No need to writeclear
all the time!CTRL + R
- Reverse search your history for a term- Use
CTRL + R
again to cycle through results
- Use
!!
Repeat the last command used in the terminal- Use
sudo !!
to repeat the last command withsudo
- Use
Cheatsheets
I've created a cheatsheet with these commands, hopefully, this will help you get used to using the commands.