Customizing the Terminal: Create Useful Aliases

Written by BinnyVA on March 28, 2009 – 12:35 am -

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…


del.icio.us | Digg it | reddit | StumbleUpon

Tags: , , , ,
Posted in Command Line, Configuration | 6 Comments »

6 Comments to “Customizing the Terminal: Create Useful Aliases”

  1. Customizing the Terminal: 5 Configuration Settings in Bash that makes you a CLI Power User | LinDesk Says:

    [...] Customizing the Terminal: Create Useful Aliases [...]

  2. Noushad Says:

    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?

  3. BinnyVA Says:

    I’m sorry – but I am not sure how it should work in the Mac system. Try posting the question in some Mac forum.

  4. Noushad Says:

    Thanks anyway.. Binny.

    Looking forward for more interesting tips.. Subscribing you :)

  5. Noushad Says:

    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.

  6. Amit Agarawal Says:

    Another interesting thing to use in the dot bashrc file is funtions. Example (all the .. alias can be done with just one function):
    http://blog.amit-agarwal.co.in/2009/04/06/quick-one-liner-bash-function-to-navigate-parent-directories-quickly/

Leave a Comment