Thursday, November 20, 2008 

Optimize bash_history

Here are some tricks on how you can optimize with some simple configurations settings the usage your bash history.

1. Don’t save duplicates:
This is my favorite…


this causes any lines matching the previous history entry not to be saved.
Other options for HISTCONTROL: ignorespace, lines which begin with a space character are not saved in the history list; erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved.

2. Size of the history:
HISTSIZE: The number of commands to remember in the command history. The default value is 500.


You can set this to 0 and disable the usage of the history file.

3. Others:
HISTFILE: The name of the file in which command history is saved. The default value is ~/.bash_history.
HISTIGNORE: A colon-separated list of patterns used to decide which command lines should be saved on the history list.

How do you set these options? Either export them in your environment in your personal bash configuration file (~/.bashrc) or in the global bash configuration file (/etc/bash.bashrc). The name of the configuration files can depend from your Linux distribution and bash version (the ones included are from Debian Linux), but you can always see your particular options using man bash. So, you can add in your configuration files the parameters you want like this:

export HISTCONTROL=ignoreboth
export HISTSIZE=500

You will need to restart your bash session in order to activate the settings. You can check if your configuration were entered correctly by typing env at the command prompt. If you don’t see your configuration in the environment variables than you have done something wrong. If you see your configuration option, then all is ok, and your setting is active already.

Add to Google

The Author

  • Nick Perrydoo
  • Spawn at Philippines
My profile


Read Ons

Article of the Day

This Day in History

Today's Birthday

In the News

Quotation of the Day

Word of the Day

Powered by Blogger
and Blogger Templates
© Copyright 2006 Ba-zoo-ra - All Rights Reserved.