As an extreme example, let me just alias a standard command to illustrate why aliasing standard commands can be harmful:
alias ls='rm'
Obviously, this is bad because it would cause a nasty surprise some day. Likewise, replacing standard commands with aliases will eventually lead to an unfortunate surprise when you least expect it.
But let me present a common scenario which will happen to nearly every Unix admin as they advance in their career:
Someday in the future, you will start a new job and will work on a new system which was set up by others. It will be three o'clock in the morning on Saturday and you aren't thinking straight and are prone to make mistakes. Your standard environment will not be available. In fact, you are root.
Given this, are you going to remember that rm
is not aliased to rm -i
? Are you going to check for your special aliases every time you log into the box? If you change root's environment, will your coworkers be happy with your change?
I am honestly on the fence about this. I have worked on thousands of systems in my career, and if I did modify the environment on all of these systems it would be hard to see the value.
Aliasing rm
to rm -i
is very common and I have seen it prevent many problems, but it has also caused many surprises and hours of extra work to recover accidentally deleted files.
So now I try to avoid aliasing common system commands. Instead I use aliases and functions to do things which the shell can't easily do. What I tend to do now is attach an extra letter to the alias, like:
# List long, with color or special characters, depending on OS
alias ll='ls -l'
# Long, with metacharacters, show dotfiles, don't show . and ..
alias lll='ls -lA'
# Long, with metacharacters, show dotfiles, show . and ..
alias lla='ls -la'
# List just the dotfiles
alias l.='ls -l -Ad .????*'
# Useful greps
#alias hgrep='history |grep ${*} |grep -v $$'
alias greph='history |grep ${*}'
alias grepp='ps -ef |grep ${*}'
### Highlight some text.
# From http://unix.stackexchange.com/questions/366/convince-grep-to-output-all-lines-not-just-those-with-matches/367#367
highlight () { grep --color -E "$1|$" $2 ; }
And perhaps I really should get rid of my final alias, because adapting to new practices takes time:
# For safety!
alias rm='rm -i'
rm -i
, it trains me a little more to automatically add the-f
flag. – Jander Mar 06 '13 at 01:34rm -i
to anything you want. Such asdel
,irm
, etc. You don't need to alias it torm
. This circumvents point 1, and by selectively usingdel
orrm
depending on what you want, you also circumvent point 2 to some degree. – Martin Tournoij Mar 06 '13 at 14:49