Customizing the Terminal: Create Useful Aliases

Terminal

This is part two of the ‘Customizing the Terminal’ series. Part one is ‘Customizing the Terminal: The Prompt‘. In this part, we’ll see how to create aliases to make working in the console easier.

How To Create an Alias

You can create a temporary alias using this command…

alias new_name='old command'

This will stop working when you exit the terminal. If you want to make the alias permanent, put the same command in your ~/.bashrc file.

There is another way to create an alias – create a executable file and place it in a folder in your path. This is not technically an alias – but it works the same way. I use this for alias that tend to change often. Its easier to find a file in a folder and edit it. YMMV.

My Aliases

This is a incomplete list of the aliases I use. Feel free to copy them to your .bashrc file.

Quick Directory Jumps

Create an alias to jump to folders you have to visit often. This is my list…

alias www='cd /var/www/html'
alias e='cd /mnt/x'

Relative Jumps

The above jumps are absolute jumps – relative jumps are possible too…

alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'

Some prefer this syntax…

alias ..='cd ..'
alias ..2='cd ../..'
alias ..3='cd ../../..'
alias ..4='cd ../../../..'

Often Used Commands

If you use some commands a lot, create smaller alternative for it…

alias x='exit'
alias q='exit'
alias rmdir='rm –rf'

Many of my own scripts are also alias’ed this way…

alias bk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/RsyncBackup.pl"'
alias rbk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/RsyncRemoteBackup.pl"'
alias nbk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/RsyncNetworkBackup.pl"'
alias bdb='perl "/home/binnyva/Scripts/Perl/Maintenance/Database Backup/Dbbackup.pl"'

Complex Commands

Create a short version of long and complex command using alias…

alias gitstat='git status | perl -pe "exit if(/Untracked files\:/)"'
alias ra='ruby script/server'
alias wikipedia='cd /mnt/x/Data/Wikipedia/mywiki; firefox "http://localhost:8001/"; python manage.py runserver 8001; '
alias sup='svn update'

and more.

Command Changes

When I came from Windows to Linux, I was used to the dos commands – but not to the linux’s mv,cp commands. So I used to have aliases for those(I don’t have these now)

alias move='mv'
alias copy='cp'
alias ren='mv'
alias del='rm'

If you go from Red Hat/Fedora to Debian/Ubuntu(or vise versa), you can set up a few alias to make the change easier…

alias yum='apt-get'

You can get a lot of ideas for more aliases by looking at others .bashrc files.

Now tell me you aliases…

15 comments

  1. Hi Binny,

    I didn’t have a ~/.bashrc file on my home folder. I created on and added alias. alias coda=’open -a /applications/Coda.app’
    It’s not working. I am using mac os x 10.5. it works temporarily in terminal.

    What could be wrong?

  2. OX 10.5 Terminal doesn’t read ~/.bashrc file natively. We need to place this line “source ~./bashrc” in ~/.bash_profile file and it works. Hope this info would be helpful to someone.

  3. Hi Noushad,

    I am not sure if it is too late to answer your question. However, if you have not
    created any alias yet on your MAC system, here we go with the solution.

    On MAC instead of .bashrc (linux system) you just open the .profile file in your home
    directory. So that if you use vi .profile, then you can use any alias just by editing this file. For example,
    alias c=’clear’. Here c command will do the work same as the command clear.

  4. Fantastic Solution from kujjhotika. Your right you need to edit the .profile file to update your new aliases. Worked a treat for me. Well done.

Leave a Reply to anurag Cancel reply

Your email address will not be published. Required fields are marked *