(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Kerio Reseller
Printer Friendly Version

Bash HISTCONTROL

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.


Hate these ads?

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.







Technorati tags:

Comments /Linux/bash_history.html


Sun Jun 8 02:22:30 2008: Subject:   anonymous


I am hoping that the following is just for example's sake, but if not, type "man watch" to learn about your new best friend- in this case the simplest version is: watch "ps -e | grep foo"

"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,"


Sun Jun 8 10:39:41 2008: Subject:   TonyLawrence


Yes, it was just for example, but keep in mind that bash runs on lots of systems that do NOT have "watch". or anything like it.

Old Unix folk like me would be unlikely to use it anyway. Out of long habit, we'd write

while :
ps -e | grep foo
sleep 2
done

or whatever. So "watch" will never be our new best friend :-)



Mon Jun 9 01:18:00 2008: Subject:   BigDumbDinosaur
http://bcstechnology.net

Hey! Watch it with the "old UNIX folks" stuff. I resemble that remark!

Add your comments




Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner





Views for this page
Today This Week This Month This Year  Overall
111631282,399 7,629

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

pavatar.jpg
More:
       - Linux
       - Unix
       - MacOSX
       - Shell




Unix/Linux Consultants

Your ad here - $24.00 yearly!

http://www.schewanick.com SCO Unix, Solaris, Linx (various), PHP, MySQL, Apache, uniBasic, dL4, Perl, System Administration and more....


http://www.breakthru.com.au SCO (Openserver and Unixware), Unix, Solaris and Linux Consulting services including: Secure Networking Solutions; Linux based Firewalls; Backup Solutions; Secure Home to Office Network Setup; Phone, Remote and On-Site Support available - Satisfaction Guaranteed!


http://echo3.net/ Unix/Linux Custom Applications, Web Hosting, C/C++ Programming Courses




Twitter
  • Jun 26 21:28
    Lost 5 cents at poker tonight. Hard to do with 10 and 20 cent betting..
  • Jun 23 07:01
    Hypermiling:







Coming Attractions

My Favorites

Change Congress

Related Posts