Limiting which commands are kept in the bash history file

By setting a certain bash environment variable, you can limit which commands are kept in the .bash_history file. The following options can be passed to the HISTCONTROL environmental variable:

ignorespace - omits commands beginning with a space
ignoredups - omits commands that match the previously run command
ignoreboth - combines ignorespace and ignoredups
erasedups - removes previous lines that match the line that was just run

To set it, simply run the following from the command line, or add it to the .bashrc or a single user's .bash_profile:

export HISTCONTROL=ignorespace

If no value is set, then all commands will be saved regardless of their content.

Printed from: http://rackerhacker.com/2008/01/29/limiting-which-commands-are-kept-in-the-bash-history-file/ .
© Major Hayden 2012.

2 Comments   »

  • robot.terror@gmail.com says:

    even better:

    export HISTFILE=/dev/null

    Nothing says "propritary one-liners" like writing history to /dev/null!

  • Antonio says:

    Sorry about resurrecting a two-year old post, but the information in it does not match my experience.

    I've found that HISTCONTROL only modifies what appears when using the up and down keys.

    If you want to omit commands from the shell history file, you can use the HISTIGNORE variable. For example, the following line in your profile will not save (consecutive) duplicates, commands starting with a space, or the 'exit' command in your shell history:
    export HISTIGNORE="&: *:exit"

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this