2

when I open terminal session A, type some commands , and then type "history" I see the commands that I was running, but then if I open another terminal session (B) and type "history" I don't see the commands that were typed in to the session A terminal.

how can I sync the history of all terminal sessions in to one file, so when I type "history" from one terminal session I will se the commands from all the sessions?

Artur Meinild
  • 21,605
  • 21
  • 56
  • 89
Eli Bukin
  • 39
  • 4
  • Probably by using some sort of PROMPT_COMMAND shenanigan and writing the commands to a textfile, then tailing that textfile when you type history Turns out there was another real solution, see below – Regretful Mar 23 '22 at 12:45
  • 1
    Does this answer your question? [Bash history handling with multiple terminals](https://askubuntu.com/questions/80371/bash-history-handling-with-multiple-terminals) – waltinator Mar 23 '22 at 15:08

2 Answers2

1

adding

shopt -s histappend and PROMPT_COMMAND='history -a'

to your .bashrc file should make your terminals append rather than overwrite the .bash_history file.

Then the history command would probably reflect whatever was typed last regardless of terminal.

Regretful
  • 111
  • 3
1

i found something that works perfectly, added the following line to .bashrc file.

export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

Eli Bukin
  • 39
  • 4