bashshellhistory

How can I see all of the bash history?


First let me show an example below.

In shell(1) I did the following command.

$ ping google.com
PING google.com (74.125.235.164) 56(84) bytes of data.
64 bytes from nrt19s12-in-f4.1e100.net (74.125.235.164): icmp_seq=1 ttl=54 time=2.85 ms
64 bytes from nrt19s12-in-f4.1e100.net (74.125.235.164): icmp_seq=2 ttl=54 time=3.42 ms

And after that, open another shell(2) and look at history.

$ history
 .
 .
 .
 8720  exit
 8721  clear
 8722  history

In this case, the shell can not see the history executed by shell(1), but I want to see all of the bash history in every shell.

So my question is how can I see all of the bash history? Does anybody know how to hack?

Thank you very much in advance!


Solution

  • You should look into the histappend shell option and the -a flag to history:

    histappend

    If set, the history list is appended to the file named by the value of the HISTFILE variable when the shell exits, rather than overwriting the file.

    history

    -a Append the "new" history lines (history lines entered since the beginning of the current bash session) to the history file.

    If you put history -a into your PROMPT_COMMAND, you'll get an always-up-to-date .bash_history file.