As a Linux user, you will tend to use the same commands time and time again. This will often tend to negatively impact your productivity. To save yourself from this inconvenience ,
alias command comes in handy. An alias is a custom shortcut that represents another command. It’s a shell command that allows you to define your own command based on a predefined set of pre-existing commands.
To put this into perspective, let’s have a look at a few alias command examples.
Listing current aliases in the system
Your Linux system comes with predefined aliases. To view pre-existing aliases, run
$ alias -p
To verify that the aliases are indeed working, we will take one example. We will run the
ls command and compare the output with
As we can see from the output above, both commands yield the same result. Executing
is the same as executing
$ ls --color=auto
Creating aliases in Linux
Let’s now learn how to create aliases in Linux. The process is quick and relatively easy. There are two types of aliases,
- Temporary aliases
- Permanent aliases
Let’s take a look at both
To create an alias use the syntax as shown below
$ alias command='command shortcut'
For instance, I’m going to create an alias to pinging Google’ DNS
ping 22.214.171.124 -c 4 .
$ alias net='ping 126.96.36.199 -c 4'
To confirm that the alias works run
Great! The alias is working. However, this will not persist after a reboot. Therefore, we need to make this alias permanent.
To enforce and make the alias permanent, you need to add it to the
$ vim ~/.bashrc
Next, append the alias at the end of the file.
Save and exit the text editor. To confirm if the alias is persistent, reboot your PC
Now check the aliases existent in your system
How to remove an alias
To remove an alias use the syntax below
$ unalias alias_name
In our example, the command will be
$ unalias net
If you check again with the
alias command, the alias will not be included in the list of aliases
That was a brief tutorial on the alias command. Your feedback is most welcome.