Ubiq
Uploaded by
2 SLIDES
21 VUES
0LIKES

How to Create Permanent Alias in Linux

DESCRIPTION

Sometimes Linux developers and system administrators need to create permanent alias in Linux. Here are the steps to do so.<br>Visit https://techosha.com/how-to-create-permanent-alias-in-linux/

Télécharger la présentation

How to Create Permanent Alias in Linux

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript

Playing audio...

  1. 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.

  2. $ list_all 2. Using Separate File If you do not want to play with any of the system files such as .bashrc or you need to create too many aliases, then you can create a new file such as .bash_aliases. $ vi ~/.bash_aliases You can add all the aliases you want to create, one on each line, as shown. alias list_all='ls -all' alias list_long='ls -l' alias cs='cd;ls' Save and close the file. Open .bashrc file. $ vi ~/.bashrc Add the following lines to it. if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi The above line basically loads .bash_aliases file whenever .bashrc file is loaded, that is, on system reboot. Among the two methods discussed in this article, the second one is recommended since it separates the aliases from important files like .bashrc. It also allows you to add more aliases to .bash_aliases file, without any additional configuration or without editing .bashrc file. In this article, we have learnt how to create permanent aliases in Linux. You can use these methods in almost every Linux distribution.

More Related