Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was reading the manpages for bash on the plane and I stumbled across the HISTIGNORE variable. To test it out, I immediately edited my .profile to define this variable:

export HISTIGNORE=ls

I tested it out and this is great! It excludes plain 'ls' commands from my history without excluding more interesting commands with lengthy paths, but having recently harvested a great deal of wisdom from SU I am eager to know what other commands superusers might recommend or other lessons learned.

What can you share about using the HISTIGNORE variable in bash?

share|improve this question
up vote 17 down vote accepted

I ignore ls without commands, bg, fg, exit, pwd, clear, mount and umount:

If you include this in your HISTIGNORE string you can suppress anything as you wish by adding a space at the front of the command:

"[ \t]*" 

This is my HISTIGNORE:

HISTIGNORE="&:ls:[bf]g:exit:pwd:clear:mount:umount:[ \t]*"

I've excluded some other stuff that I have in there that are repetitive commands that are unique to my server. Anything you do that is simple is a good thing to exclude.

I have other stuff which I have forgotten to add but I'm miles away from my Linux box so I am going off of memory.

share|improve this answer
3  
If the value of HISTCONTROL includes "ignorespace" or "ignoreboth", commands that begin with a space are omitted from history. If the value includes "ignore dups" or "ignoreboth", it's the same as "&" in HISTIGNORE. – Dennis Williamson Jan 14 '11 at 23:03
    
To me it has also proven useful to histignore the history command itself. – con-f-use Apr 17 '13 at 21:07
    
using "[ \t]*" ignores command starting with a space or t. You want HISTIGNORE=$'&:ls:[bf]g:exit:pwd:clear:mount:umount:[ \t]*' – Gregory Pakosz Oct 22 '15 at 19:11

Don't save trivial one and two character commands on the history list:

HISTIGNORE='?:??'

If the extglob option is enabled, you can also use extended patterns, e.g.

HISTIGNORE='a*( )'
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .