Forgetful Bash

Interesting forum topic about saving the bash history. I guess there is currently a “bug” where if you close the terminal window, rather than exit the shell, bash doesn’t save the history file, like it normally does.

A workaround is to add the ‘history -a’ command to your prompt command. The -a option tells bash to append any new history lines to the history file, thus you append to it every command. This has the side effect of having every opened terminal inherit the current history of all your bash shells, as well as save the commands from all of them into a central place. I like this idea, as I have always been bothered by the fact that the history is only from the last closed bash shell, losing any interesting commands I had previously.

Another option discussed is the -n option, which tells bash to read any new commands added to the history. This essentially means that all opened terminal windows share a history.  So here’s the line to add to your .bashrc:

export PROMPT_COMMAND="history -a; history -n; $PROMPT_COMMAND"

I’ll have to try both.

[SOLVED] Terminal doesn’t remember last commands


  1. drcouzelis says:

    Thank you very much. I’ve been looking for this information. :)

Leave a Reply