Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
Shared history seems to be possible with some effort, see this. I haven't tried it myself, so I don't know how reliable it is. zsh, on the other hand, has it built in. –  Thor Jul 26 '12 at 16:59
1  
The part you added to your question is a duplicate of an existing question: Is there a way to make the history when pressing up in bash shared between shells? –  Gilles Jul 26 '12 at 23:29
    
I think the whole thing is a duplicate; I'm going to close it –  Michael Mrozek Jul 27 '12 at 3:01
    
I am using zsh & oh-my-zsh now. This feature coming by default. –  mesuutt Oct 10 '13 at 15:22
add comment

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.

3 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
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 ? –  mesuutt Jul 26 '12 at 14:26
add comment

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.

share|improve this answer
add comment

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'

share|improve this answer
    
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
add comment

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