The bash shell is supposed to be used on the screen.
Insert two statements in ~ / .bashrc:
shopt -s histappend PROMPT_COMMAND="$PROMPT_COMMAND;history -a"
The first command adds commands to the history file, but does not overwrite it, and the second command saves each command immediately after its execution, and not at the end of the session.
To expand on my answer, the history of each bash session that you opened is stored in memory until you log out and close the session. Then it will overwrite the bash history file. These commands will be added to the history file, and then after each command are reset to the file.
source share