10. Alias - A Linux Command for Shortcut Creation
Contents
Sometimes a frequently used Linux command can be very long, and when that happens, we need the alias command to help simplify the work of human input.
We can create aliases in two common ways, one for temporary aliases and the other for permanent aliases.
Let’s take a look at its help documentation:
|
|

Check alias's definition and usage
We can use the alias command to view the shortcuts owned by current user:
|
|

List all the available shortcuts
Create Temporary Alias
Let’s create a temporary shortcut for a text that needs to be displayed:
|
|

Create a shortcut named show_greetings
Let’s see if the temporary shortcut we just created exists:
|
|

show_greetings shortcut created successfully
We can use it as directly as we use commands:
|
|

Use the created shortcut, it runs echo command and output the text
Remove Temporary Alias
We can use the command to remove the temporarily created shortcut:
Let’s take a look at unalias help documentation:
|
|

Check unalias's definition and usage
Let’s remove the show_greetings shortcut:
|
|

Remove the show_greetings shortcut
Let’s check to see if the shortcut has gone:
|
|

show_greetings shortcut removed successfully
Create Permanent Alias
We can add or remove a permanent shortcut by modifying the .bashrc file in the current user’s home directory.
We use the vim text editor to open it:
|
|
Once we open the bashrc file, we can see some predefined permanent shortcuts:

show_greetings shortcut removed successfully
We can add the commands we used earlier to create the temporary shortcut:
|
|

we added the show_greeting shortcut in the bashrc file
After saving and exiting, let’s have a check on the shortcuts list.
Aas we can see, the permanent shortcut we just added does not appear in the shortcuts list:
|
|

the show_greetings shortcut doesn't not exist
We can use the source command to re-import the bashrc file into the running system, so that we can use the permanent shortcut we just created without having to re-login:
|
|

Check source's definition and usage
Let’s re-import bashrc:
|
|

re-import the bashrc
The newly added permanent shortcut, show_greetings, should be visible and usable:
|
|

the permanent show_greetings shortcut exists
References How to Create and Use Alias Command in Linux
Author Dong Chen
LastMod Mon Feb 11 2019