Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 2 down vote accepted

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

PROMPT_COMMAND="$PROMPT_COMMAND;history -a"

after

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.