Reputation: 5183
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!
Upvotes: 65
Views: 236030
Reputation: 9675
history 1
worked for me..
This will show the history starting from line 1.
Upvotes: 6
Reputation: 4793
As several have noted, you need to use shopt -s histappend
. Check by running shopt
and verifying that histappend is 'on'.
To ensure that each command (across multiple concurrent shells) appears in the history for each of those shells, add this at the end of your .bashrc file:
# Skip if not an interactive shell
if [ -z "${PS1}" ]; then return; fi
export PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND}"
-a: appends the new history lines (history lines entered since the beginning of the current Bash session) to the history file.
-c: clears the history list.
-r: reads the current history file and append its contents to the history list.
Run source .bashrc
or create new sessions and in several terminal windows enter the comment #Tn
in each. Then on one terminal, enter history | tail -N
to see the last N lines. You should see all of the comments entered on the different terminals.
It may be helpful to add the following to /etc/profile.d/bashrc.sh
in order to get a timestamp on each line of the history:
if [ -z "${PS1}" ]; then return; fi
export HISTTIMEFORMAT='%F %T '
The result looks like this:
[moi@laBoheme ~]$ history | tail -4
3292 2019-01-22 12:41:25 # T1
3293 2019-01-22 12:41:32 # T2
3294 2019-01-22 12:41:44 # T3
3295 2019-01-22 12:41:50 history | tail -4
Upvotes: 4
Reputation: 1118
You can install something like Advanced Shell History, which will log each command to a sqlite3 database. It comes with a tool for querying the database from the command line. https://github.com/barabo/advanced-shell-history
With this setup, you will have a unified view of command history across all sessions. You also get things like command history for the current working directory (or subtree), command exit code, command duration, etc.
Full disclosure: I wrote and maintain the tool.
Upvotes: 6
Reputation: 4210
cat ~/.bash_history
would also work, although I tend to just use
vim ~/.bash_history
and then use /
to search
Upvotes: 75
Reputation: 133
try this:
Edit your .bashrc and append this to it's end:
shopt -s histappend
PROMPT_COMMAND="history -n; history -a"
unset HISTFILESIZE
HISTSIZE=2000
source: http://subbass.blogspot.com.br/2009/10/howto-sync-bash-history-between.html
Upvotes: 7
Reputation: 224904
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.
Upvotes: 29