5

Possible Duplicate:
Is there a way to make the history when pressing up in bash shared between shells?

I am opening more than one console tab and I want to use commands that executed from first console tab from new opened console tab.

Is this possible to use commands that executed from first tab from second tab that not opened currently?

How can I use console history synchronously between consoles?

marked as duplicate by Michael Mrozek Jul 27 '12 at 3:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

7

According to the documentation, history -a should append the ``new'' history lines (history lines entered since the beginning of the current bash session) to the history file.

  • Thanks @choroba.This is good and solve first question. I added a new question to post.How can I use history synchronously?.This is possible ? – Mesut Tasci Jul 26 '12 at 14:26
1

You could probably do it with a series of settings, such as (and I haven't fully tested this)...

export PROMPT_COMMAND='history -a; history -c; history -r'

That will cause the most recent command to be appended to your .bash_history file, then clear your shell history, then re-read the .bash_history file, each time the shell prompt is printed... so each time you run a command.

So, commands from one terminal will be appended to .bash_history every time they're run, then the second terminal will pick them up when it re-reads the history file.

Now, keep in mind that this is not realtime, as your second shell will not re-read the history file that was just written by the first shell until a command is run, but it's probably as close as you'll get with bash.

You may find value in setting your HISTCONTROL envvar to ignoredups or erasedups, or this option may not work so well for you.

export HISTCONTROL='erasedups'

  • The last time we had this question,, I suggested history -a; history -n. I didn't test it either. – Gilles Jul 26 '12 at 23:41
  • actually, i went ahead and did this on my dev system, and it's working pretty well. rotating shells are always 1 command behind, but a simple test or echo foo triggers history to update, and then you have access to the same command history from multiple shells. Thanks, for the hint on -n, i'm going to play with that tomorrow. :) – Tim Kennedy Jul 27 '12 at 2:38
  • For some reason, this creates a lot of duplicates in my .bash_history file. Since I'm saving the time stamp for each command (by using HISTTIMEFORMAT="%d/%m/%y %T "), I can see that the all have the same timestamp. They don't show up as duplicates when I run history, though. – HelloGoodbye Jan 30 at 16:28
  • 1
    That may have been a result of me not using the exact line you suggested, but export PROMPT_COMMAND='time (history -a; history -c; history -r)', in order to see how much this slowed my system down :-) (this never detected anything longer than 0.07 seconds in real time, btw, so not an especially large delay) – HelloGoodbye Jan 30 at 16:51
0

Part 2: According to the documentation history -r should read the history file in and replace the current history record.

Not sure what you mean by 'synchronously' but if you mean the automated synchronization of the histories of 2 console windows/tabs then I think the answer is NO. You have to do it manually.

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