I found that my ~/.bash_history has record of all commands I typed in different terminal tabs. But when I do reverse-search (CTRL+r) it only shows commands from that particular tab from which I'm doing reverse search. How to enable reverse search so that it looks through all commands in ~/.bash_history rather than just current tab history?
Asked
Active
Viewed 1,838 times
3
1 Answers
3
Most of this is covered here.
To answer your precise question- By default, the history file is read once at shell startup, and written once at shell exit. To fetch commands that appeared in the history file since the shell start, use the history update command history -n
, or the combination history -a ; history -c; history -r
. The difference between those is how the histories are merged.

Matei David
- 579
-
Thanks, do you mean to say I cannot do reverse -search in terminal tab A for the commands I typed in terminal tab B; unless I run
history -n
in terminal A? – user13107 Aug 10 '16 at 03:33 -
1The "once" rule applies to both. To get commands from A to file: have A either exit, or explicitly call
history -a
. To get them from file to B: have B either start after file is updated, or callhistory -n
orhistory -r
(the merging order differs between those). This is explained in the other answer. – Matei David Aug 10 '16 at 04:02 -
I have accepted this answer but I wish there was an easier way to do this without manually running
history
commands when working across tabs. – user13107 Aug 11 '16 at 02:47 -
Thank you, but there is- see the linked question. The solution involves using
PROMPT_COMMAND
. – Matei David Aug 11 '16 at 03:13
ksh
will do this; in window1 I can type a command and it immediately shows up in the history on window2. Sometimes you may need to press RETURN to make it resync properly. Indeed, if you have an NFS mounted$HOME
then this history update may appear across multiple servers. – Stephen Harris Aug 10 '16 at 16:10