Creating alias for Linux command line

Command-line alias is a quick and useful tool for those repetitive commands which we are continuously executing in our terminal. We can transform large and painful commands into a one word length alias.

Let’s see how to make it:

First of all, we have to open a new terminal in our favorite Linux distribution.

Now edit the .bashrc file which is located in our home directory. To do this we have to type the next command in the terminal:

sudo nano ~/.bashrc

Then nano editor (you can use your favorite text editor) will be open and we can add a new alias (one per line).

When defining a new alias it must have the following structure:

alias ALIAS_NAME='OUR_ALIAS_COMMAND'

For example, we are going to add this new alias:

# Download all servers backups
alias remote_backups='python /var/www/scripts/remote_backups.py'
 

After edit our .bashrc file, we have to save the file changes.

Last step is loading the .bashrc file into the current command prompt executing the following command:

source ~/.bashrc

Now we are ready to execute our aliases in the terminal.

# Alias execution example (in a terminal)
$ remote_backups