How to remove alias on Linux

The purpose of this tutorial is to show how to remove an alias on a Linux system. Aliases can be created to either be permanent or temporary, but it is possible to remove them either way. Check out the steps below to see how.

In this tutorial you will learn:

  • How to remove temporary alias on Linux
  • How to remove permanent alias on Linux
How to remove alias on Linux
How to remove 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 remove temporary alias on Linux




If you have created a temporary alias by using the alias command, you can use the unalias command to remove it.

For example, let’s set a temporary alias:

$ alias docs='cd /home/linuxconfig/Documents'

Now, to remove this alias, we would execute:

$ unalias docs

You can verify that the alias has been removed by trying to use it, or by checking the list of configured aliases on your system:

$ alias -p

How to remove permanent alias on Linux

If you have created a permanent alias by editing the ~/.bashrc file, you just need to open this file and remove the corresponding line.

  1. You can open the file with nano or your preferred text editor.
    $ nano ~/.bashrc
    
  2. In this file, locate the alias that you wish to remove. Simply backspace the line to delete it completely.
    The .bashrc file contains the permanent alias we wish to remove
    The .bashrc file contains the permanent alias we wish to remove
  3. When done, save your changes to the file and exit it. Then, execute the following command to make the changes take effect:
    $ source ~/.bashrc
    
  4. You can verify that the alias has been removed by trying to use it, or by checking the list of configured aliases on your system:
    $ alias -p
    

Closing Thoughts




In this tutorial, we saw how to remove an alias on a Linux system. The steps to remove a temporary alias versus a permanent alias are different, but are easy enough to do for any user. You may use the alias command again in the future to create another temporary alias, or edit the ~/.bashrc file to create a permanent variable that persists after subsequent reboots.



Comments and Discussions
Linux Forum