Create alias on Linux Ubuntu

Steps to Setting Up Aliases in the bash-shell 

Wouldn’t it be easier to just type something like the following?

tailmyless

Luckily for us, this is simple to do in the bash-shell.

1. Open your .bashrc

Your .bashrc file is located in your user directory. Open it in your favorite text editor.

$ vim ~/.bashrc

2. Go to the end of the file. 

In vim, you can accomplish this just by hitting “G” (please note that it is capital).

3. Add the alias. 

A simple way to chain commands in Linux is to use the && operator. This operator will run a set of commands and only continue to the next command if the previous one was successful.
For our example, we might have an alias that looks like this:

alias tailmyless='cd /home/myuser/public_html/less && lessc -c style.less > ../style.css && cd ../ && tail style.css'

This looks complicated but it really isn’t. Here’s the basic format:

alias aliasname='commands'

One gotcha is that there cannot be a space between the “aliasname” and the EQUAL sign. Also, there can’t be a space between the EQUAL sign and the opening quote for the command.

4. Write and close the file. 

In vim, hit ESCAPE to get to normal mode and run the following command to write and quit:

:wq

5. Install the .bashrc

The new .bashrc would be installed the next time you log out and log back in, but if you are impatient like me and just want it installed now, you can just source the file.

$ source ~/.bashrc

Well, that’s it. You now can alias until your heart’s content. Remember, a few seconds saved here and there can dramatically increase your efficiency!