Creating custom Linux Terminal (Bash) commands


Bash has a very interesting feature that allows you to create «shortcuts» for more complex commands. The resource is called «alias», or «nickname / pseudonym» of English, this allows you to streamline many tasks of your day to day.

Understand resources as a way for you to abbreviate more complex commands, for example, to update your Ubuntu you could use the following command:

sudo apt update && sudo apt dist-upgrade

It wouldn’t be nice if instead of typing all of this you just typed:


And was the result exactly the same as the previous command? So, this is exactly what the “alias” in the Bash settings allows you to do.

To better understand, check out the video of our partners of Oficina do Tux:

The operation is simple, you basically need to edit the file .bashrc inside yours home to be able to create these “shortcuts“, You can use the Gedit or any other text editor for that.

Let’s do an example.

Open the .bashrc:

gedit ~/.bashrc

Scroll down the page until you find an “aliases” section for organization purposes, so you can create as many as you like and leave them all together:

Alias ​​Terminal Ubuntu

The working metric is simple:

alias atualizar="sudo apt update && sudo apt dist-upgrade"

The phrase should always start with the word “alias”, as indicated, the next word should be the “alias” you want to use, that is, the command that will be used instead of the larger command, indicated in the example in red, right after we will have an equal sign, opening single quotes and as highlighted in blue, you must enter the command that will be executed when the “alias” you defined is typed in the Bash terminal, remember to close the single quotes at the end and save the file so that Bash can interpret it.

You can create as many as you want, for whatever purpose you want, all of which will make your terminal very intuitive.

See too: Do you want to dominate Bash? Discover our Terminal course

To reverse the process, just delete the lines you added or comment them using “#” at the beginning of the sentence, without the quotes.

Another way to reset the settings is to delete the .bashrc file inside your home, as soon as you open the terminal again, or end the session, log in and open the terminal again it will be recreated.

This procedure affects only your user, if you wanted these changes in Bash to work for any user on your computer, instead of editing the file inside the home you should edit the file bash.bashrc inside of /etc.

To the next!