[Ilugc] LJ Tech Tip

  • From: sbharathi@xxxxxxxxxxxxx (Bharathi Subramanian)
  • Date: Wed Nov 28 16:30:20 2007

LJ Tech Tip: Can't Get Enough of Aliases

Aliases are really handy, if you seldom use the command line and your
memory is as bad as mine. They are also an essential time saving tool if
you live on the command line. But, they clutter up your command line
history file and make it harder to use, too.

There is a bash setting that can be used to prevent this by excluding some
of the more common commands like ls, etc.... Ones that you don't really
need in the history file. If you list all of your aliases there it will
exclude them as well. If you can remember an alias' name you don't need to
look it up in the history. :-)

If you put these two entries in your ~/.bash_profile or ~/.bashrc file the
following environment variables will be available every time you start up a
shell, and really reduce history clutter.

export HISTCONTROL=erasedups
export HISTIGNORE="dir*:cd *:ls*:less *:&"

HISTCONTROL=erasedups is an option that removes all previous duplicate
lines before saving to the history list. The option "ignorespace" prevents
lines which begin with a space from being saved in the history list. This
allows you, on an individual basis, to select which commands go into the
history file by putting a space before the command.

HISTIGNORE="" takes a list of commands (including shell wildcards) that you
don't want in the historyfile. A colon is used as the separator and "&" is
a special symbol that causes history to ignore consequtive duplicate
commands.

When HISTIGNORE is used with SUSE 10.3, there has to be a space before the
"*" in the commands cd and less -- but if you used a space with dir or ls,
it did not work properly. So you will have to do a little experimenting and
testing to get it working the way you want.

To immediately reload changes in ~/.bashrc, simply type source ~/.bashrc
and press enter, in a terminal window.

HTH :)
--
Bharathi S

Other related posts: