Use your terminal like a pro

0liverFlow
7 min readApr 16, 2023
Terminal tricks

Using the terminal to execute commands on your system is generally faster than using the GUI (Graphical User Interface) most of the time. In fact, it can help you execute complex operations in just a matter of seconds.

Nevertheless, in my day to day life in the IT field, i have noticed that though several people master very well the different GNU/Linux commands, they struggle with their terminal when it comes to perform tasks such as deleting a long text, re-typing a previous command, or moving from a tab to another one and so on.

If you’re someone who really likes using their keyboard or wants to increase their productivity, this article is for you.

Through this article, you will learn how to use:

  • The terminal shortcuts and split your terminal screen
  • The aliases
  • The user-defined variables
  • The reverse search history

At the end of the day, these tricks will significantly help you, use your terminal efficiently.

Note 📝: The shortcuts discussed in this article are the default ones, present in most GNU/Linux OS. Thus, they should normally work on your system as well.

GNU/Linux Terminal Shortcuts

To refresh your mind, a terminal is a program that allows you to interact with the operating system through a command-line interface (CLI).

When using your terminal, you can perform several manipulations from moving to a specific position, deleting a character or copying a character . A very common way to do that, consists of pressing the same key several times or even use the mouse sometimes. However, this can sometimes be time-consuming and tiresome especially when the command is long.

Luckily for us, the terminal’s shortcuts can tremendously be useful in this case, see that they will allow us to perform our tasks faster by only using a combination of characters.

To grasp very well the different shortcuts, we will cover them step by step.

Navigation shortcuts

Navigation shortcuts are shortcuts that are used to move the cursor or switch between tabs for instance.

The figure below is a list of navigation shortcuts that you can use in your terminal to move faster:

Navigation shortcuts

Just pick these shortcuts one after another, and use them daily in order to get quickly familiarized with them.

Let’s now cover the deletion shortcuts.

Deletion shortcuts

Deletion shortcuts are shortcuts used to delete a character, word or a entire line. Instead of repeatedly using your delete and backspace key to delete a text on your terminal, you can use these practical shortcuts below:

Deletion shortcuts

Edit shortcuts

Edit shortcuts are shortcuts used to edit a text on a terminal. The figure below is a list of some interesting edit shortcuts:

Edit shortcuts

View shortcuts

As the name implies, view shortcuts are shortcuts used to change the text view on a terminal. These shortcuts can allow you to zoom in, zoom out or minimize and maximal a terminal window. The figure below is a list of some interesting view shortcuts:

View shortcuts

Other shortcuts

This is a list of other shortcuts you can use as well:

Other useful shortcuts

Note 📝: For those of you, who are using MacOS, you need to replace home, end, Page Up and Page Down keys respectively by fn+Left Arrow, fn+right Arrow, fn+Up Arrow and fn+Down Arrow.

Great! Let’s now see how to split a terminal screen.

Split terminal screen

In this section, i will use ctrl + shift + D and ctrl + shift + R to split my screen horizontally and vertically respectively.

To see what shortcuts to use in your case, you can take a look to the shortcuts section in Files > Preferences > Shortcuts.

The figure below is an illustration of how to split a screen horizontally:

Horizontal split screen

To move from one split screen to another, i use alt + ↑ ↓ because i horizontally split my screen. If i had vertically split my terminal, i would use instead alt + ← → key combination.

Aliases

An alias is a shortcut name for a command.

Here is how you can use it.

In the following example, we’ll execute the command used to update and upgrade a Debian based distribution. The command in question is:

sudo apt update && sudo apt upgrade -y

How will you feel if you have to type this command every time that you need to update and upgrade your system?

Boring 😑. Right? That’s where aliases come into play.

To replace the command above with an alias, you only need to enter in your terminal the following command:

alias update="sudo apt update && sudo apt upgrade -y"

And that’s it. However, the created alias is not permanent which means that it will be deleted as soon as you close your terminal.

To change this behavior, you can add the created alias directly to your $HOME/.bashrc file.

To do that, you can use of the command below:

echo "alias update="sudo apt update && sudo apt upgrade -y" >> $HOME/.bashrc

Please, make sure to use the >> , otherwise you will lose any customizations made to your Bash shell such as the environment variables, shell options and so on.

Note 📝:

  • Here, we used $HOME/.bashrc to save our created alias. Nevertheless, a good practice will be to save it into $HOME/.bash_aliases file. You can check out this article if you want to learn more about how to do it.
  • Make sure to not create an alias with the same name that a command that already exists. By doing so, you will unwillingly hide the original command by the alias which can then cause issues in the long run.

The figure below in an illustration of how to use aliases:

Alias command

Let’s explain some of the commands used in the figure above:

  • which update : help us to check the existence of a command called update.
  • alias update="sudo apt update && sudo apt upgrade -y" : create a new alias called update.
  • alias -L : display all the aliases.

Moreover, i could save my alias permanently by redirecting the alias command used above to $HOME/.bashrc file.

Excellent! Now that we have a better understanding of how useful an alias can be, let’s take a quick look to user-defined variables.

User-defined variables

Sometimes, when playing CTF (Capture The Flag), you need to specify the target IP address or the target URL by typing them on your terminal.

This can be frustrated especially if you have to use them in several commands.

One way to resolve this, is by storing them in variables, and then use these variables instead of using the IP or the URL themselves.

Note 📝: The variables that we are going to create are called user-defined variables, simply because we’re the ones who created them in contrast to shell variables that are already defined by default by the shell.

Here, is an example of how to do that.

Let’s say that our target is using the following URL:

https://LikeAndSubscribeIfYouEnjoyTheContent.com/Medium/Readers/

Of course, this url doesn’t not exist yet, and is only used for demonstration purposes.

Let’s now store this URL in a user-defined variable:

User-defined variable

As you can see, instead of typing the URL every time, we can just simply use our defined TARGET_URL variable instead.

Note 📝: This is only one example of how user-defined variables can be used. However, you can use in other scenario such as in script automation and so on.

Super! It’s time now to delve into our last section which is reverse search history.

Reverse search history (reverse-i-search)

One way to find a command we previously executed, consists of using our keyboard’s Up arrow and Down arrow keys.

However pressing over and over these two keys can be extremely tedious.

A great alternative to that consists of using the ctrl + r shortcut which is useful for searching through our command history.

A reverse-i-search is a search backward starting at the current line and moving ‘up’ through the history as necessary. This is an incremental search. (source)

In fact, all we need is to first press the ctrl + r combination, then enter the first letter or two first letter of our command, then hit ctrl + r until we find the command we were looking for.

Here is how to do that:

Reverse-i-search

Let’s recap!

In this article, we covered some of the interesting terminal tricks that we can use to optimize our time when using our terminal.

Though this can significantly contribute to make your tasks faster, it requires you to practice daily before being able to master them very well.

That’s all guys! Hope you learnt something!

Do not forget to click on the little clap icon below if you enjoyed the content and to subscribe to my newsletter to keep up with my latest articles.

Contact

LinkedIn : https://www.linkedin.com/in/konateolivier/

GitHub : https://github.com/0liverFlow

--

--

0liverFlow

Cybersecurity Enthusiast | Enjoy breaking and building stuffs