Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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 superuser.com/q/421544/4714 –  glenn jackman May 7 '12 at 14:53

3 Answers 3

up vote 4 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=/home/<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

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

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.