Post Image

Linux Add Command Alias Without Logging Out

In this post I will walk you though adding a command alias on your linux system for your user, and make that take effect without the need to log out and back in again.

 

Create Command Alias

The first step that we need to do is create the command alias for the user, to do that in your users profile edit the .bashrc file. If this is for a different user, you will need to specify the path to their .bashrc file. The example below is what you need to edit your own using Nano.

$ nano ~/.bashrc

Page down to the bottom of that file and add the alias you want at end of the file

alias apache='sudo service apache2'

The syntax is "    alias <your_alias>='command_to_alias'   "

 

Reload bashrc

Ordinarily you would log out and back in, but if you wish to not do that you can just reload the bashrc file and it will begin to take affect.

Below is the command to reload your bashrc file.

. ~/.bashrc

 

And now to test, issue the alias command and make sure it works.

$ apache status
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
~ Output Truncated ~
$

 



Comments (0)
Leave a Comment