10 Terminal Tricks Most Developers Don’t Know (But Should)

10 Terminal Tricks Most Developers Don’t Know (But Should)

These small tricks made a big difference in my daily workflow — and they will for you too.

Rishabh Agarwal

Terminal is central to all of software engineering. It certainly is one of those places where a developer spends majority of their time. Terminal, if used properly, can accelerate developmental work. On the other hand, if used incorrectly, terminal may feel like a resistance!

For most modern developers, including myself, using the terminal can be challenging, as it offers little to no support for mouse input.

Almost everything must be done using keyboard shortcuts and commands!

But it’s only after mastering these shortcuts and commands that we truly unlock the terminal’s full potential. From making quicker edits to retrieving past commands efficiently, learning these tricks allows us to do much more with far less typing.

In this post, I’ve shared some tips and tricks I’ve picked up over the course of my software engineering career, in the hope that other developers can discover them faster than I did.

Reverse Searches Using Ctrl + R

More often than not, we find ourselves using the same commands when working on a project. Instead of typing them repeatedly or copy-pasting them, we can take advantage of the terminal’s history. The terminal keeps a record of all previously used commands, which can be easily searched.

Just use the combination Ctrl + R and start typing the command you are looking for. The list of commands from history are filtered based on what you type.

Source

Reverse search is one of those features that is extremely useful and saves a lot of time. If you’re not already using it, try to get the hang of it and watch your productivity go up!

Bonus Tip: You can add comments at the end of your command to work as tags. This way, searching your command becomes even more easy!

For example, run your command like command #useful . Then you can use the reverse search to find the exact command by tag “useful” - Ctrl + R #useful .

Clear Screen Using Ctrl + L

The clear command is the most common way to clear the content of your terminal screen. If you are someone like me, you probably clear your terminal after every few commands!

Instead of typing out the word “clear”, you can make use of the shorthand Ctrl + L. It is much quicker than using the command.

Source

In addition to being quicker, it is a more versatile option! Many terminals & command line tools like Python or PSQL that don’t support the clear command responds to this shortcut.

Jump to the start of a command Using Ctrl + A

Ever pasted or typed a long command into the terminal, only to realize there’s a mistake near the beginning? Without mouse support, you’re stuck holding the left arrow key to navigate back — an annoyingly slow process if the command is lengthy.

Do you know there exists a shortcut Ctrl + A to help you jump to the start of a command?

Using this shortcut, you can directly jump to the start of a command you are writing on your terminal!

Source

Jump to the end of a command Using Ctrl + E

Similar to Ctrl + A, there exists a command to jump to the end of an active command on your terminal. Use Ctrl + E to jump to the end of the command!

Incorporating Ctrl + A and Ctrl + E in your workflow is going to seriously improve your speed of using terminal!

Use Option/Alt + Arrow to move the cursor word-by-word

Another key combination to improve how you move your cursor is Option + Left/Right Arrow (or Alt + Left/Right Arrow on Linux). Using this key combination, we can move the cursor on terminal word-by-word instead of character-by-character!

Use this key combination to quickly reach to any part of your command!

Source

Rerun last command using !!

In Bash environments, !! (double exclamation) serves as a shorthand for the preceding command. This is same as hitting an up-arrow and an enter.

If you only intend to run the last command, the double exclamation approach does not provide any benefits over the standard up-arrow and then enter approach.

However, if you want to add prefix or suffix to your previous command, this works best. Just use !! in-place of your previous command.

Here is an example ~

~ mkdir temp

~ sudo !!

Ctrl + U to delete from cursor to beginning of the line

Ctrl + U is yet another key combination that not many people know about. Using this, you can delete all the characters from the position of your cursor to the beginning of the line.

Combining it with Ctrl + E, you can use it to delete the entire command in just two key strokes!

Ctrl + K to delete from cursor to end of the line

Another key combination that is used to jump to the end of a line is Ctrl + K. Use it in conjunction with Ctrl + A to delete an entire command in just two key strokes!

Double-tab to see all possible completions

When typing out a command on terminal, you can use double Tab to either autocomplete (if there is only a single option) or see all possible completions!

Using double tab saves you from a lot of typing and helps you make lesser typing mistakes.

"cd -" to switch to the previous directory

If you use terminal, cd has to be one of your most used command. It is used for moving from one directory to another. A nice shorthand that I use for this command is cd -. Using this command takes me to the last directory.

Note: It is not necessarily the last directory always!

For example, if from directory /user/projects I change to /users/games. Then typing cd — would take me back to the projects folder!

Source

And that’s a wrap! Thanks for reading the complete article.


Rishabh Agarwal

Written by Rishabh Agarwal

1.7K followers

42 following