I use mainly Terminator, and it's usually opened with 3 split terminal windows. I also use Gnome terminal for various reasons.
I'm wondering how is bash history handled in this case as I sometimes miss previously issued commands when I run history

For example, my prompt shows current bash history line (\!) and if I launch Terminator with 3 split terminal windows I get same history line (let's say 100) on all terminals. Which history will be saved?

Also launching Gnome Terminal after using Terminator I get line 100 at startup regardless all commands issued before in Terminator

link|improve this question

67% accept rate
feedback

2 Answers

up vote 3 down vote accepted

The bash session that is saved is the one for the terminal that is closed the latest. If you want to save the commands for every session, you could use the trick explained here.

Anyway, you'll need to take into account that commands from different sessions will be mixed in your history file so it won't be so straightforward to read it later.

link|improve this answer
isn't it stored separately for different TTL?? – Vineet Menon Nov 18 '11 at 7:02
Excellent. Thanks for explanation and solution. I tried with export PROMPT_COMMAND='history -a; history -r' and I got some strange history line numbers in terminal - after issuing some command history line number jumps by 2000 instead by 1, which is strange but it behaves as said - all terminals history is saved. – zetah Nov 18 '11 at 7:07
@VineetMenon For more details look here. Interesting parts: When the shell starts up, the history is initialized from the file named by the HISTFILE variable (default `~/.bash_history'). [...] When an interactive shell exits, the last $HISTSIZE lines are copied from the history list to the file named by $HISTFILE. – jcollado Nov 18 '11 at 7:36
feedback

I use separate history files for each shell. I did a mkdir -m 0700 ~/.history then added

HISTFILE=~/.history/history.$$  
HISTFILESIZE=0  
HISTFILESIZE=4096  
HISTSIZE=4096  

to my ~/.bashrc. Every now and then, I remember to du -sk .history and clean it out. It's nice to have every command I've typed preserved for me.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.