Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 354
diveintohacking Avatar asked Feb 27 '13 16:02

diveintohacking


People also ask

How can I see my shell history?

Searching shell command historyOpen a terminal application on your Linux or Unix and type history to list all commands. To search for a command in the history, press ctrl+r multiple times.

Where is bash history kept?

In Bash, your command history is stored in a file ( . bash_history ) in your home directory.

Why does bash history disappear?

If you're losing bash history and you have multiple sessions at a time, it's because each session is overwriting the other sessions' history. You probably want to tell bash to not overwrite the history each time, but rather to append to it. You can do this by modifying your . bashrc to run shopt -s histappend .


3 Answers

cat ~/.bash_history

would also work, although I tend to just use

vim ~/.bash_history 

and then use /to search

like image 69
etusm Avatar answered Oct 09 '22 00:10

etusm


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.

like image 39
Carl Norum Avatar answered Oct 08 '22 22:10

Carl Norum


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

like image 7
jfelipesp Avatar answered Oct 08 '22 22:10

jfelipesp