Table of Contents
Use alias command to create custom commands. This article will show you how to create and use it in Linux.
In the article about the types of commands available in Linux, I mentioned the alias command. Now I will say more about it.
The purpose of the alias command in Linux
There is a fact that takes place in Linux system administration, there are very long commands that we have to execute. And even, we may have to execute it many times every day.
You will be tired of repeating those long commands. And the alias command solves that problem.
So what does it do, it simply creates a custom command that represents your long command line. And instead of having to type the long command, you have a custom command.
Use alias in Linux
In the article I mentioned above, a command I have to repeat many times when working with InfluxDB is the login to its command window.
influx -ssl -unsafeSsl -host 192.168.10.10And now, I want a more concise command to type instead of the long command above. For example, I want the custom command to be login_influx.
Recommended Reading: Use “type” command to display a command’s type

Create temporary alias
To create temporary alias, we use the command structure below.
alias custom_command='string'With:
custom_command: the name of the custom command you want to use.string: Long string of commands that you need to use alias instead. In this example, the main string isinflux -ssl -unsafeSsl -host 192.168.10.10
Now type the following command to create alias.
alias login_influx='influx -ssl -unsafeSsl -host 192.168.10.10'Now you can type login_influx to see if it is available.
Why is it temporary when you create alias as above? Because this alias command is only loading in the current terminal session. If you exit the terminal session that is working, this alias will be deleted.
Create alias permanently
To fix the temporary alias, we will create alias permanently. Whenever you login to the terminal, alias will be there for you to use.
Now open the ~/.bashrc file and add the above alias command to the end of the file.
Or you can run the following command to quickly add the file to the end.
echo "alias login_influx='influx -ssl -unsafeSsl -host 192.168.10.10'" >> ~/.bashrcThis file works to run alias for your session.
And then, you run this command to reload the ~/.bashrc file immediately.
source ~/.bashrcNow try typing the login_influx command on the terminal.
login_influxThe commands work with alias
List all available alias commands
$ aliasDelete an alias of a certain command. With example above.
$ unalias login_influxDelete all alias commands.
$ unalias -aConclusion
The alias command can be said to be one of the most useful commands in Linux. I myself use it very often, and believe me, you will be the same.
Hopefully with the above article, you can save time during your work. Help it less boring.
(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).