History in Bash
Useful tips:
Put this into ~/.bashrc
:
HISTSIZE=5000 #controls how much history is loaded into memory
HISTFILESIZE=10000 #controls how much history is saved on disk
#By default bash overwrites the history file at the end of each session
#which is a pain if you open multiple shells (not all history is saved)
#use this to append to the history file
shopt -s histappend
However if you want each history item to be available in every shell as soon as you press enter rather than when you close the shell, you’ll need to use this in addition to the above:
Put this into ~/.bashrc
:
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
Use the source ~/.bashrc
command or close and reopen your shells for the changes to take affect.
Digital Ocean has a nice blog post on history in bash