Most Unix shells read old history from a file, once – when the shell is started – and when you close that shell, the history is written to the file again.
Usually the old contents are simply overwritten, so if you do something like...
- login to sessions A and B
- A and B read the same contents of
~/.history
- run command
test
in A
- A adds
test
to its in-memory history
- B doesn't know about the command
- logout from A
- A overwrites
~/.history
with its history, which has test
- login to session C
- C reads contents of
~/.history
, with test
- logout from B
- B overwrites
~/.history
with its history, which doesn't have test
- logout from C
- C overwrites
~/.history
with its history, which has test
then test
will be saved to the history file after step #3, but step #5 will discard it, and step #6 will add it again...
Some shells have an "append history" option that avoids this (e.g. shopt -s histappend
in Bash).
If you want to have completely separate histories, an easy way is to just symlink your history file to /dev/null
.