How to make bash (Terminal.app) remember history of previous sessions

bashhistoryterminal

In my computer at work, my bash shell remembers history from previous sessions, even if I just opened a new terminal.
In my computer at home, this doesn't happen.
I have the same OS 10.6.8 in both machines and I don't have any history related setting in .bash_profile.
How could I set this up on my home computer so it remembers history across sessions?

Best Answer

You'll need to tell bash where to keep your history file, and how many lines to keep:

# Set the location of your HISTFILE
echo "export HISTFILE=/Users/<USERNAME>/.bash_history" >> ~/.bash_profile

# Number of lines to keep (1000 in this example)
echo "export HISTFILESIZE=1000" >> ~/.bash_profile

# Set how many commands to keep in the current session history list
echo "export HISTSIZE=80" >> ~/.bash_profile

# Ignore commands that start with a space
echo "export HISTIGNORE=\"&:[ ]*:exit\"" >> ~/.bash_profile