Quantcast

Bash HISTCONTROL

Get the WebProNews Newsletter:


[ Business]

I happened to come across Linux Tips: take control of your bash_history.

This explains that setting “export HISTCONTROL=ignoreboth” causes Bash not to store duplicate commands in history. For example, if you are checking “ps” waiting for some process to end:

ps -e | grep foo

and keep pressing up arrow every few seconds to repeat it, you’ll end up with a long list of those in your history if this isn’t set. If it is set, you get only the last.

Actually there’s much more to this than that little post exlained.

First, there’s actually several values HISTCONTROL can take. On newer bash, it can be set to “ignorespace”, “ignoredups”, “ignoreboth” or “erasedups”. Bash 2.05 doesn’t have “erasedups”.

If you want manual control over history, set “ignorespace”. Then remember to use a space to precede any command you don’t want to remember in history.

Bash ignores leading spaces, so ” ls” is as good as “ls”, but with “ignorespace” set, ” ls” won’t be saved.

The “ignoredups” setting ignores repeated lines. Typing “ls” twenty times in a row only ends up with one of them in history.

However, typing “ls” and then “ps” and then “ls” again will store “ls” and “ps” every time – unless you have bash 3 and set “erasedups”. If that’s set, no duplicates get entered in bash history at all.

You can also control bash history with HISTIGNORE. For example, if I “declare -x HISTIGNORE=ls:ps”, neither “ls” or “ps” will appear in my history.

To ignore all two character commands, use “declare -x HISTIGNORE=’??’”.

I don’t like extra commands cluttering up my history file, so I use “ignoreboth”.

When available, I use “erasedups”, but if you are using history as a record of commands rather than just for the convenience of repetition, you don’t want that.

*Originally published at APLawrence.com

Add to Del.icio.us | DiggThis | Yahoo! My Web | Furl

A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com

Bash HISTCONTROL
Comments Off
Top Rated White Papers and Resources

Comments are closed.

  • Join for Access to Our Exclusive Web Tools
  • Sidebar Top
  • Sidebar Middle
  • Sign Up For The Free Newsletter
  • Sidebar Bottom