Append to ~/.bash_history "immediately"

Bash normally waits until a session (terminal) is closed before it writes commands to the history.

You can add a call to history -a to PROMPT_COMMAND to make bash to append your history to ~/.bash_history every time it displays your prompt.

PROMPT_COMMAND="history -a; $PROMPT_COMMAND"

The environment variable PROMPT_COMMAND is executed when bash is about to display your prompt.

The command history -a appends the current history to ~/.bash_history.

Tagged linux and bash.

 

This page was generated at 4:16 PM on 26 Feb 2018.
Copyright © 1999 - 2018 Rodney Waldhoff.