Super User is a question and answer site for computer enthusiasts and power users. 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

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

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

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? – Nick Heiner 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .