How to create permanent alias on Linux

Creating an alias for use on the command line can save the user from typing long commands, common options, or typos. This will save you some time and repetitive keystrokes, and ultimately make your command line experience even more efficient. In this tutorial, we will take you through the step by step instructions to create a permanent alias on a Linux system.

In this tutorial you will learn:

  • How to create permanent alias on Linux
  • How to use alias on Linux
  • How to view configured aliases
How to create permanent alias on Linux
How to create permanent alias on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to create permanent alias on Linux



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!

  1. To create a permanent alias, we will need to edit the ~/.bashrc file. You can open this file with nano or your preferred text editor.
    $ nano ~/.bashrc
    
  2. At the bottom of this file, you can add your permanent alias. As an example, we will make a simple alias docs which executes the command cd ~/home/linuxconfig/Documents/.
    alias docs='cd /home/linuxconfig/Documents/'
    
    Adding our new alias to the .bashrc file
    Adding our new alias to the .bashrc file
  3. After saving your changes and exiting the file, execute the following command to make the changes take effect:
    $ source ~/.bashrc
    
  4. Now we can use our newly configured alias in the command line.
    $ docs
    
    Using the new alias in command line
    Using the new alias in command line
  5. To check your configured aliases, along with the new one you just set, execute this command:
    $ alias -p
    
    Viewing the configured aliases on our Linux system
    Viewing the configured aliases on our Linux system

Closing Thoughts




In this tutorial, we saw how to create a permanent alias on a Linux system. As this is a permanent alias, the setting will persist after subsequent reboots. If you need to remove the alias in the future, you will have to delete the line from the ~/.bashrc file.



Comments and Discussions
Linux Forum