Often Linux developers and system administrators need to create shortcuts to Linux commands. They are very useful if you have long commands that you need to use frequently but do not want to type the entire line every single time. Linux allows you to create aliases for this purpose. There are two types of aliases –temporary and permanent. Temporary aliases last only as long as your terminal session whereas permanent aliases last even after system reboot. In this article, we will learn how to create permanent alias in Linux.
How to Create Permanent Alias in Linux
You can create permanent aliases in two ways. We will look at both these methods one by one.
1. Using .bashrc
In this approach, we place the command for alias in any of the files that are automatically loaded every time during system reboot. This will make them permanent. For example, .bashrc file is loaded on every system reboot.
Here is the syntax to create alias in Linux.
alias alias_name = command_to_be_aliased
Let us say you want to create an alias for the command ‘ls -all’.
sudo alias list_all='ls -all'
Open .bashrc file in text editor.
$ vi ~/.bashrc
Add the following line at the end of the file.
sudo alias list_all='ls -all'
Save and close the file. Now whenever your system boots .bashrc file will be loaded every time. Thereafter, you can call ‘ls -all’ command using the following alias.
$ list_all