Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I run history, I get a list of commands. However, it does not appear to be complete, even for a given period of time. (It doesn't feel like it has continuous coverage of the past N commands - it feels like some are missing.) Also, the output of history is different in different terminal tabs. Is this because the history isn't written to disk until the tab is closed? Does that explain why certain commands seem to get lost, because they are overwritten by closing tabs?

I'm on OSX 10.8 for what it's worth.

share|improve this question
add comment

2 Answers

Different terminals are running different instances of your $SHELL (which is BASH probably since you are on OSX). Each instance keeps its own history which is concatenated into the global session history when that particular BASH instance exits.

You can try this by opening two terminals, running some commands, then closing both terminals and opening a third. The commands from the (now closed) two previous terminals will now be in your history.

There are also some BASH options to remove duplicate commands, look at your $HOME/.bashrc and check if you have a line like:

export HISTCONTROL=ignoredups

That option tells BASH not to save duplicate commands. So, if you run ls 10 times, it will only be saved once.

share|improve this answer
add comment

The shell history exists per instance of bash. It is read in when bash starts, and is written out when bash exits. Closing the tab forcibly kills bash, rendering it unable to write out the history as normal.

share|improve this answer
    
What do you mean by 'closing the tab'? How should I end the session to let bash write the history? –  Rosarch Jan 14 '13 at 20:20
    
You should use exit, or press Ctrl-D on an empty line. –  Ignacio Vazquez-Abrams Jan 14 '13 at 20:22
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.