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:
|
|
We can use the alias command to view the shortcuts owned by current user:
|
|
Create Temporary Alias
Let’s create a temporary shortcut for a text that needs to be displayed:
|
|
Let’s see if the temporary shortcut we just created exists:
|
|
We can use it as directly as we use commands:
|
|
Remove Temporary Alias
We can use the unalias command to remove the temporarily created shortcut.
Let’s take a look at its help documentation:
|
|
Let’s remove the show_greetings shortcut:
|
|
Let’s check to see if the shortcut has gone:
|
|
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:
We can add the commands we used earlier to create the temporary shortcut:
|
|
After saving and exiting, let’s have a check on the shortcuts list.
As we can see, the permanent shortcut we just added does not appear in the shortcuts list:
|
|
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.
Let’s take a look at this command’s help documentation:
|
|
Let’s re-import .bashrc:
|
|
The newly added permanent shortcut, show_greetings, should be visible and usable:
|
|
References How to Create and Use Alias Command in Linux
Author Dong Chen
LastMod Mon Feb 11 2019