0

I understand that command line history in the case of bash is saved in .bash_history.

When you open a terminal emulator window in Ubuntu/MacOS and work in it, the history is not saved in .bash_history yet but when you close the window, the history of the session will be appended to the end of the .bash_history file.

My question is: where are the history saved during the session, before I close the emulator window?

The reason I care is that sometimes I mess up wile working in it and the terminal window simply freeze. When I force close it, I lose all the history contained in the session. I want to be able to retrieve them.

Lassi
  • 831
  • 6
  • 15
  • @mosvy, not on MacOS. It's more complicated there. See https://unix.stackexchange.com/q/473581/135943 – Wildcard Dec 04 '19 at 23:10
  • So, what's the value of PROMPT_COMMAND in bash on MacOS? I guess they may be already calling history -a from it, in which case the OP can retrieve the history of recently crashed sessions from ls -t ~/.bash_sessions/ | head? –  Dec 04 '19 at 23:36

1 Answers1

0

You could try one of the suggestions here, addition to your .bashrc is immediate, although there are some disadvantages.

I added the following to ~.bashrc and have experienced no real issues

HISTSIZE=5000
HISTFILESIZE=10000
shopt -s histappend

export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

Whether this works in MacOS or not I don't know

bu5hman
  • 4,756