How to Alias a Command in Linux

Just a quick post on a simple way to add a command alias to your bash terminal. Open up the .bashrc file in your home directory for editing. I used nano for this:

nano ~/.bashrc

Next scroll to the very bottom and add a new line. The format of the line is:

alias {name}="{command}"

For example I created a simple alias for the common ping command by adding the following line to my .bashrc file.

alias p="ping"

Now I only need to type p as my command instead of typing out ping.

This is obviously a very simple example but you can make it as complex as you want. For example you can alias a command with many options to a more simple word saving you a lot of extra typing!



Be the first to comment

Leave a Reply

Your email address will not be published.


*