Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As far as I can tell, the history of an individual shell is only appended to the .bash_history file when the shell is closed. This means that I frequently lose individual shells' histories on crashes / kernel panics.

Why does the history only get written on closing a session? Is there a way to have each command written at the time of execution? Is there any reason I should not want to have each command written at the time of execution (e.g., performance issues when writing to an enormous bash_history file)?

(I'm using Mac OS X 10.6 and running many tabbed terminals simultaneously with iTerm. I have histappend set along with some other options.

export HISTSIZE=1000000
export HISTTIMEFORMAT="%d/%m/%y %T "
shopt -s histappend


share|improve this question
up vote 3 down vote accepted

You're missing one line in your .bashrc. Add:



shopt -s histappend

PROMPT_COMMAND is executed just before the next prompt is printed (IIRC). You're right about when the history is written, by the way. The modified prompt command will flush the history.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .