More Durable History In Bash


tl;dr : On reboot, shell history is hard to re-initialize

I open a lot of shells and generally they are running in tmux.

My current bash setup writes history files to HISTFILE=~/.history/history.$(date +%Y%m%d-%H%M%S).$$.log . Each shell instance writes to their own history file.

If the computer crashes or reboots, I would have to manually go find the history file and read it back it to get my history back.


Make a function to symlink the $HISTFILE to a local file.

And set an environment variable so I know where I ran the alias ( and thus where the symlink is ).

function local-history {
    LOCAL_HISTDIR=$(pwd -P)
    export LOCAL_HISTDIR
    ln --symbolic $HISTFILE .$(basename $HISTFILE)

Then when you go back into the directory after a reboot, you can reset the history for your shell.

history -r <file>

See Also