Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

up vote 8 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
2  
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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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