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
add comment

2 Answers

up vote 3 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 "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
2  
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
add comment

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
add comment

Your Answer

 
discard

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.