How to sync terminal session command history in bash?
Add this line to .bashrc
:
export PROMPT_COMMAND="history -a; history -n"
Open new terminal and check.
Explanation
history -a
appends new history lines to history file.history -n
tellsbash
to read lines that is not read from history file to current history list of session.PROMPT_COMMAND
: contents of this variable is run as regular command beforebash
show prompt. So every time after you execute a command,history -a; history -n
is executed, and yourbash
history is synced.