What determines what shows up in the bash history command?
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.
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.