Alias Command: Making work easier by using alias for complex commands

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello friends. We really like working in the terminal, as it is very efficient and suits both sysadmin and desktop users. However, the use of aliases sometimes goes unnoticed and is a trick that, when used well, can save a lot of time in the terminal. This can be done using the alias command.

What does the alias command do?

The alias command tells the Linux terminal to replace one string with another when executing commands. That is, by using alias you will be able to place a simpler name for the execution of a more complex command. Kind of like an alias in the real world.

By default, aliases persist for the current session. This means that as soon as you close the terminal, this alias will disappear; however, this behavior can be modified to make the alias permanent.

So, why use aliases? The short and precise answer is that frequently used commands can be invoked using a different and preferred term.

Besides that, alias is present in every Linux distribution out there, so you can start using it right away.

Using the alias command

If you just run the alias command, you will be able to know all the aliases that have been created. Some of them already come by default in the system.

alias

By default, the use of aliases is simple. For example, to create a new Alias, just run the command.

alias name='[command]'

This syntax is worth noting:

  • The command you are going to define must always be enclosed in single quotes.
  • There must be no space between the name and the command.

As I said before, this definition will last until the terminal is open.

A practical example can be to update the operating system. In the case of Debian, Ubuntu and derivatives, we know that to update the system, you must run these two commands.

sudo apt update
sudo apt upgrade

But you could create an alias for that called up and so instead of typing those commands individually, you could make the whole process easier.

alias up='sudo apt update && sudo apt upgrade -y'

Now run the new alias

up
Making work easier by using the alias command
Making work easier by using the alias command

You will see how the command works, and it is a way to speed up your work in the terminal.

Make a permanent alias

Again, these changes are not permanent, to make them permanent, we have to do some things on the system.

What we have to do is edit the .bashrc file and add the alias right there.

nano ~/.bashrc

And at the end of the complete file, add your alias.

alias up='sudo apt update && sudo apt upgrade -y'

Save the changes and close the editor. Now yes, after rebooting or shutting down the computer, the alias will be preserved.

That alias will only work for the current system user. If you want it to work for any user, do the same process but in the /etc/bash.bashrc file.

Conclusion

Alias is a simple command that, when used well, can contribute to improving the workflow in the terminal.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook