HomeBooksDigital GardenStoreContact

Useful Command Line Shortcuts

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 with CTRL+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 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

Text manipulation

  • CTRL + T - Swap two letters between the cursor
    • Example: this if the cursor is between the h and i it turns into tihs
  • ESC + T - Swap two words between the cursor
    • Example: this text will become text this
  • 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 clear all the time!
  • CTRL + R - Reverse search your history for a term
    • Use CTRL + R again to cycle through results
  • !! Repeat the last command used in the terminal
    • Use sudo !! to repeat the last command with sudo

Cheatsheets

I've created a cheatsheet with these commands, hopefully this will help you get used to using the commands.

Dark Theme

terminal shortcuts dark

Light Theme

terminal shortcuts light