The alias Linux Command

Hello friends. Using the Linux terminal is not as complex as many would have us believe. But sometimes we indeed have to get used to it a little bit. On the other hand, many Linux professionals use the terminal on a fairly continuous basis and require some kind of help. Today we are going to talk about the alias command with which you can adapt the terminal to you and your workflow a bit more.

What is the Alias command?

Basically, the alias command is used to customize the terminal interface of the session because this command tells the Linux terminal to replace one string with another when executing commands.

This means that a command such as rm -r /home/user/Documents/* can be called remove to avoid having to type it all out.

It is important to mention that aliases persist for the current session. So once the session is terminated, they will disappear although there is a way to make them permanent.

So, this command is very easy to use but at the same time useful, so that we can have a better workflow in the terminal and its commands.

Using the Alias Linux command

If you run the command alias just like that, it will show all the aliases that the system has. In the case of Debian 11

alias

We will get this output on the screen.

To define an alias, simply invoke the command along with the alias name and the command to receive it, as follows.

alias remove="rm -r /home/user/Documents/*"

This way every time you run remove it will remove the entire contents of the Documents folder or rm -r /home/user/Documents/*.

And so you can make aliases for the commands you use the most. Also, with just one easy-to-remember word you can execute them.

Remember that once the session ends, these aliases will be lost.

Removing an alias from the system

If you don’t want to logout to remove the alias from the system, you can do it manually by running the unalias command, for example

unalias [alias]

In the above example if we wanted to remove the remove alias then we would run

unalias remove

And then there will be no trace left in the system.

Making an Alias permanent on the system

If you want your alias to be permanent, then you have to add it to the .bashrc file if you use bash. If you use another shell, then modify the shell’s configuration file.

nano ~/.bashrc

And add your alias to the end of the file.

alias remove="rm -r /home/user/Documents/*"

Save your changes and remember that all of these changes will be applied after a reboot.

Conclusion

The alias command helps us to customize our work in the terminal a bit. If you are a heavy user of this tool then you will appreciate having a command that allows you to set aliases to the commands you use the most.

So, I hope this short and simple post has helped you and we ask you to share it and help us to grow.

Scroll to Top