Skip to content

Instantly share code, notes, and snippets.

@fprieur
Created July 29, 2016 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fprieur/f6d80a7a6d8f114b4d3b0c769f089886 to your computer and use it in GitHub Desktop.
Save fprieur/f6d80a7a6d8f114b4d3b0c769f089886 to your computer and use it in GitHub Desktop.
Preserve bash history in file
# Maximum number of history lines in memory
export HISTSIZE=50000
# Maximum number of history lines on disk
export HISTFILESIZE=50000
# Ignore duplicate lines
export HISTCONTROL=ignoredups:erasedups
# When the shell exits, append to the history file
# instead of overwriting it
shopt -s histappend
# After each command, append to the history file
# and reread it
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"

From http://lpetr.org/blog/archives/preserve-bash-history

It’s actually fairly straightforward to preserve the history. Open up your ~/.bash_profile configuration file in an editor of your choice such as nano. Once you have it open, add these lines at the end:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment