Customizing the Terminal: Create Useful Aliases

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


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/"'
alias rbk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/"'
alias nbk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/"'
alias bdb='perl "/home/binnyva/Scripts/Perl/Maintenance/Database Backup/"'

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 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…

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