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?

  • If you don't mind switching shells, 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. Aug 10, 2016 at 16:10

1 Answer 1


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.

  • 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, 2016 at 3:33
  • 1
    The "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 call history -n or history -r (the merging order differs between those). This is explained in the other answer. Aug 10, 2016 at 4: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, 2016 at 2:47
  • Thank you, but there is- see the linked question. The solution involves using PROMPT_COMMAND. Aug 11, 2016 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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