mardi 19 avril 2011

Optimising bash history

One of the issues which I have been facing when using bash and working with multiple terminals open, is that command history would not be saved from one shell to another, and that what would be saved would appear to come randomly from one of the open terminals.


After some digging on the web, I found the following settings useful in order to improve the situation, which I have added to my .profile

  • shopt -s histappend If set, the history list is appended to the history file when the shell exits, rather than overwriting the history file.
  • export PROMPT_COMMAND='history -a' Set this option to append every line to history individually
  • export HISTCONTROL=ignoreboth This tells bash not to save duplicates lines in the history file
  • export HISTSIZE=2000 This tells bash to save the last 2000 lines of history, instead of only the last 500