How to create useful aliases on Ubuntu / Linux Mint

by Nenad Zivkovic

Updated on December 12, 2014


Since you are reading this tutorial, I am assuming that you are new to Linux world. I guess you are probably wondering what are aliases, or maybe you know the theory but you do not know how to create them.

Aliases are shortcuts for terminal commands. So far, you probably have had to use commands like:

 

sudo apt-get install "some package"

 

Writing of long commands can be boring and fatiguing, especially if you have to use them over and over again. Instead of writing long instructions, you can make aliases. For example, instead of writing previous command:

 

sudo apt-get install

 

you can write:

 

get

 

In order to be able to do this, you need to create an alias in your .bash_aliases file ( if you are using Ubuntu ) or .bashrc file if you are using Linux Mint ( Ubuntu version ). Lets see how you can do all of this.

1. Go to your home folder.
2. Turn on "show hidden files" in your file manager. Usually you can find it under  file manager "view" menu.
3. If you are using Ubuntu, create .bash_aliases file if it do not exists already. Note that you have to use this . ( dot ) in front of file name. Dot is hiding files and folders. If you are using Linux Mint ( based on Ubuntu ) create .bashrc file.
4. Inside this file you create aliases like this ( you have to write them ):

 

alias get='sudo apt-get install'

 

You first have to write the keyword "alias". Then you need to write the name of your alias ( what you will type in terminal in order to issue your command ). In this case name is "get". Finally, you have to assign the command that will be executed when you use your alias. Note that we are writing commands inside single quotes.

Now you know how to create aliases. Let me show you few useful ones that I am using:

 

#lamp
alias ar='sudo service apache2 restart'
alias www='cd /var/www/sites'

#php server
alias phps='php -S localhost:8080'

#commands
alias mod='sudo chmod'
alias get='sudo apt-get install'

#git
alias gita='git add .'
alias gitc='git commit -m'
alias gitp='git push origin master'
alias gits='git status'
alias gitl='git log'

#composer
alias ci='composer install'
alias cu='composer update'

#codeception testing
alias tc='codecept'
alias tr='codecept run'
alias tru='codecept run unit'
alias trf='codecept run functional'
alias tra='codecept run acceptance'
alias tb='codecept build'
alias tboot='codecept bootstrap'

 

If you want to use, for example, git commit alias, you would have to write your command in terminal like this:

 

gitc "my commit"

 

If you look at my Codeception testing aliases, you can see that every alias starts with the letter "t", which stands for test. So for example alias "tru" means test run unit. Create aliases that are meaningful to you and easy to remember.

Note*: if you have terminal already opened at the moment you create aliases, you will have to restart it so aliases can start working.

Thank you for reading this tutorial, I hope it was useful to you. Cya


If you want to post a comment, you need to signup and create a profile.

4 comment(s) :


#35 User Pic
Nenad Zivkovic March 13, 2015, 10:03 pm

@Kam Fazelpoor

Thanks Kam :)

#29 User Pic
Kam Fazelpoor March 12, 2015, 11:43 am

Nice article, thank you for sharing your know how? Your version of Yii2 is the best I have seen so far perusing for all things Yii2 advanced.

#9 User Pic
Nenad Zivkovic December 12, 2014, 11:22 pm

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum...

#8 User Pic
Freetuts Test December 12, 2014, 11:22 pm
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.