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?


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.

  • 7
    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
  • 2
    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:


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.