Preserve bash history across multiple sessions
Copying & pasting long command lines across open terminal sessions feels so wrong. Specially since Ctrl-R
could find that hairy one-liner after just a few keystrokes. Except it is buffered in another session. Fortunately, bash is flexible enough to commit every command to the history immediately:
export HISTCONTROL=ignoreboth:erasedups # no duplicate entries
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it
# Save and reload the history after each command finishes
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
Discovered at Preserve bash history in multiple terminal windows.
Written by Stanislaw Pusep
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#