How to create and use bash alias on linux?
Bash Alias is a shortcut that we can manage / set according to our own needs. For example, when we use the CLI on linux, sometimes we feel a command is too long to type. For example, when we want to check the nginx service with the systemctl status nginx command and we feel lazy to type that long command, we can make an alias (for example) checknginx. So that every time we type checknginx in the terminal, it will run the command systemctl status nginx. Of course this will make it easier for us to shorten typing in the CLI.
Create Bash Alias
Let’s just go ahead, to create a Bash Alias we can open the ~/.bashrc
file with your favorite editor, here I am using the vim editor.
vim ~/.bashrc
then more or less you will see this:
You can start creating aliases right after this line
# Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi
right away, we can create an alias with a format
alias yourShortcut = 'originalCommand'
Later it will be more or less like this (for example the bash alias I have)
Also Read : How to import database in MySQL Docker
Using Bash Alias
After we have finished creating aliases, before we can use them first run this command:
source ~/.bashrc
This command is used to read the changes to the ~/.bashrc
file that we have edited. After that, we can use all the aliases that we manage in the file.
Keep in mind, the existence of this alias bash really helps us all, but too many aliases are sometimes not good. Moreover, (for example) we create the alias on a server that is not only us who access it, of course if there is no coordination with the team about the alias it will be confusing.
Yes, that’s the information about create and use bash alias on Linux that I can share. Hopefully this information can be useful ^^,
SOURCE : Digital Ocean