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.
To always use vim instead of vi, and to make sure that whenever
there is a system 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
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 the aliases that are set globally, just enter 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’
seems viru is so lazy..!!
To prevent the effect of aliases defined for a word, token or a command, use unalias.
/home/viru$ unalias jbin
There is another way to accomplish this,that is by using quotes (‘’) after a command.the following lines show how.
/home/viru$ alias same
/home/viru$ same ‘’
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’) then the actual command will be run.(ie df’’ would run /usr/bin/df instead 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.