Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Also asked at – glenn jackman May 7 '12 at 14:53
Best answer:… – mles Mar 22 at 21:01
up vote 5 down vote accepted

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
share|improve this answer
That should all be unnecessary by default. The default bash configuration (at least on Mac OS X) enables command history. – Chris Page May 8 '12 at 8:50
Key word, /should/. If his isn't recording history, this will force bash to keep the history on init. – Aaron Lake May 8 '12 at 12:29
Not merely should, but will unless something has been done to suppress the default history behavior, in which case, just slamming some values into these variables is merely papering over the actual problem. If this answer resolves the issue, then something else is really messed up and should be fixed to avoid other issues. – Chris Page Dec 30 '15 at 12:23

I had this problem and what worked for me was create a file called .bash_sessions_disable in my user folder (~/).

Basically OS X create history files in .bash_sessions folder for each session (in my case, one for each Tab). And even properly closing these sessions, OS X don't replay the historical to .bash_history.

Creating the .bash_sessions_disable you disable this behavior.

touch ~/.bash_sessions_disable
share|improve this answer

I just discovered I had a similar problem, though my employer only has two Macs, and neither sits on my desk. Unacceptable, but a battle for another time.

Anyway, at home, Mac Mini (migrated from MacBook Pro) did not cooperate even after setting .bashrc and/or .profile. Then I discovered that my ~/.bash_history file was mysteriously owned by root. Had to do this:

sudo -iu root
cd ~(myusername)
chown (myusername) .bash_history

(Yes, I know it can be done in fewer commands. Habit.)

Then I exited Terminal, and started up a new one. Woot! All sorts of history previously lost came rushing back. How very nice.

Likelihood anyone reading this has accidentally put themselves in this predicament: 0.2%. I'm sure I mucked this up when over-zealously "fixing" something else.

share|improve this answer

I had a similar problem as well, no history recorded. The given solutions didn't work, but at long last I found out that the problem was as simple as a missing .bash_history

The solution was to go to /home/[username]/ and add a file .bash_history, so

nano .bash_history

and then type anything in the file (otherwise it won't be created), exit and save. After this the history started functioning normally.

share|improve this answer
If this resolves the issue, then something else is wrong and should be fixed to avoid other issues. If you start up Bash when there is no history file, it will create one. If it doesn’t try to create one, or it is unable to create it, there’s something wrong with some shell startup script or the home directory permissions. For example, see the answer: – Chris Page Dec 30 '15 at 12:25

This answer from this Reddit thread saved me:

It's probably RVM preventing the exit "hook" for bash_sessions to run. If you comment out the following line in your .bash_profile, it should work.

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.