This is a short one, but someone may find it useful.
Normally when you log out of bash it will write the history to ~/.bash_history. This is all well and good until you have multiple terminals open, because the last terminal to close will overwrite whatever is in ~/.bash_history.
I’ve written a little bit of bash code that I now put in my ~/.bash_logout file to take whatever is in the history buffer at logout and store it in a file something like ~/.bash_history_archive/2009/04/23/210400_12345.
1 2 3 4 5 6 7 8 9 10 11
Well that’s it.