Saturday, 28 January 2012

alias

alias is one of those commands for people who want to be lazy. you can use alias

in situations where it is too time consuming to type the same commands again and again.

But avoid aliases to commands like rm, kill etc.

Example. 1)

Toalways use vim instead of vi, and to make sure that whenever

there is asystem crash, network failure etc during editing ,

all the contents are recovered, use the alias as follows.

/home/viru$ alias vi = ‘vim –r’

To make this happen every time you work after logging in, save the above line in

your .profile

i:e in the file$HOME/.profile

after saving it in .profile do not forget to run it.

ie /home/viru$ . $HOME/.profile

|

|

a dot here is necessary.

Example2) after running .profile ,to view all thealiases that are set globally, just enter alias.

/home/viru$ alias

alias ls=’ls –lrt’

alias psu=’ps –fu $LOGNAME’

alias df =‘df –gt’

alias jbin=’cd /home/viru/utils/java/bin’

alias jlib=’cd /home/viru/utils/java/lib’

seemsviru is so lazy..!!

Example3)

To preventthe effect of aliases defined for a word, token or a command, use unalias.

/home/viru$ unalias jbin

/home/viru$ jbin

Jbin:not found

There is another way to accomplish this,that is by using quotes (‘’) after a command.the following lines show how.

/home/viru$ alias same

alias same=’/opt/bin/samefile.exe’

/home/viru$ same ‘’

same:not found.

The effect of alias was nullified for the word same. If you use double quotes after an aliased command name ,(eg: alias df =‘df –gt’) thenthe actual command will be run.(ie df’’ would run/usr/bin/dfinstead of df-gt)

Aliases which are defined outside a script or in your .profile do not work inside scripts. so make sure not to use aliased words in a shell script to contain their actual values used outside.