In gui mode, when a user has more than one terminal open, how do the terminals rewrite the history file of that user? the reason I ask is because, it is quite possible that in each of the terminals the user ends up executing different commands. So, does the history file end up saving the commands from all the terminals or only from the first one to be opened? Or is there some other kind of scheme that is employed to tackle this situation?
It depends entirely on how the shell chooses to handle it
bash by default will overwrite the history file with the local history of each shell as it exits, so the last shell to exit wins. The
histappend option will cause it to append to the master history instead (
shopt -s histappend).
zsh does the same by default, and has a few options for dealing with it:
appendhistory-- The history of each shell is appended to the master history file as the shell exits
incappendhistory-- The master history file is updated each time a line is executed in any shell, instead of waiting until that shell exits
incappendhistory, but also pulls changes from the master history file into all running shells, so you can run a command in one shell and then hit Up in another shell and see it
I originally got this idea from the O'Reilly "Unix Power Tools" book.
.profile I set:
Every time my
.profile gets read, I get a new history file named with the PID of my session. If I have multiple logins, each login gets a unique history file. Works in
If you're just opening new terminals in an X session, those usually aren't login shells, but you can configure them to act as login shells. For example,
rxvt +ls will start
rxvt as a login shell. Check the docs for whatever terminal you're using.
Also, unless you're using a
.bash_logout file (or some other means) to clean up, you'll eventually have a crapload of
set savehist = (5000 merge) merges