How can I see Bash history from more than one terminal session in Ubuntu? [duplicate]
Possible Duplicate:
Can history files be unified in bash?
I use Ubuntu Server 9.10 and I would like to be able to see my bash history for more than one terminal sessions. I.e. my last 200 commands or so, even if I have been logged out in between.
When I use the history
I just see all commands from my actual terminal session. How can I see more command history from Bash? Is there any specific settings for bash that I should change from the default values in Ubuntu?
I don't have a ~/.bash_history
file. But I have an ~/.bashrc
with HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
and HISTCONTROL=ignoreboth
echo $HISTFILE
/home/sanoj/.bash_history
echo $HISTSIZE
500
echo $HISTFILESIZE
500
echo $HISTCONTROL
ignoreboth
UPDATE: I am now trying Ubuntu Server 10.10 in VirtualBox. If I just turn off VirtualBox without the shutdown command, then next time when I boot, the commands from the last session is not saved in the history file.
The commands are only saved if I shutdown the machine with the shutdown command. E.g. shutdown -P 0.
This must be the reason to my problem. So I have to figure out how to save the command-history more often. E.g. after each command.
Solution 1:
You can use
history -a
to immediately append the in-memory history to the history file. One terminal session can't see another's unless this is done or the other is exited.
You can use
history 200 | less
to see that number of entries.
In addition to HISTSIZE
see the entry in the Bash man page concerning HISTFILESIZE
.
Solution 2:
Once you log out the history gets appended to the file ~/.bash_history
. Have a look in there.
By default it will remember your last 500 commands. If you want to save more set the variable HISTSIZE
in ~/.bashrc
.
I also do add ignoredups
to HISTCONTROL
(with HISTCONTROL=$HISTCONTROL:ignoredup
). This makes duplicate consecutive commands to be save only once.
Have a look at man 1 bash
for what else you can tune about the history.
Solution 3:
bash history is usually loaded when the shell begins running, and is saved when it is exited normally. You can use history -a
and history -n
to override this, but not automatically unless you abuse $PROMPT_COMMAND
or something similar.