MacOS – Bash History missing from Terminal

bashmacosterminal

After an OS update, my bash history is suddenly gone – typing "history" at a terminal window (sudo or standard) yields only the commands entered after the upgrade.

What could have happened here?

Best Answer

In this particular case, I found that the history had gotten into a strange state.

Nothing was present in the .bash_history file, however, there were plenty of saved sessions in the .bash_sessions folder of the user root (e.g. ~).

Once inside the .bash_sessions folder, I found there was a file with a GUID and a .historynew extension.

Ex:

~/.bash_sessions/{GUID}.historynew

That file contained the lost commands, but somehow was no longer attached to the saved history for the user. From there I simply piped the output and appended to the .bash_history file, and started a new session and everything was back. One way to do this:

cat {GUID}.historynew >> ../.bash_history