Useful Command Line Shortcuts
3 min read
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+Uwas deleting the line, but it's just cutting the whole line, you can paste the text with
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 line
CTRL + E- Moves the cursor to the end of the line
CTRL + arrow keys- Moves the cursor from word to word
ALT + B- Moves the cursor back from word to word
ALT + F- Moves cursors forward from word to word
Cutting and pasting
CTRL + W- Cut the word left of the cursor
CTRL + K- Cut the entire text at the right of the cursor
ALT + W- Cut the entire text at the left of the cursor
CTRL + U- Cut the entire line
CTRL + Y- Paste the previous cut text
CTRL + T- Swap two letters between the cursor
thisif the cursor is between the h and i it turns into
ESC + T- Swap two words between the cursor
this textwill become
ESC + U- Uppercases text right of the cursor - moves cursor to the end of word
CTRL + Q- Deletes text from line - clears line only
Other useful shortcuts
CTRL + L- Clears the terminal -> No need to write
clearall the time!
CTRL + R- Reverse search your history for a term
CTRL + Ragain to cycle through results
!!Repeat the last command used in the terminal
sudo !!to repeat the last command with
I've created a cheatsheet with these commands, hopefully, this will help you get used to using the commands.