Exit the terminal and restart it. Now, history
will show you all these commands, both from within tmux
as before.
The history of a session is only committed to the .bash_history
file once you exit a session. When you start a new session, .bash_history
is read and the command will be available. The reason it works like this is that it allows to evaluate the history of each session separately.
It is possible to configure your terminal to immediately have issued commands available in the history of all sessions.
From here:
Add the following to your ~/.bashrc:
# Avoid duplicates
HISTCONTROL=ignoredups:erasedups # Ubuntu default is ignoreboth
# When the shell exits, append to the history file instead of overwriting it
shopt -s histappend # In Ubuntu this is already set by default
# After each command, append to the history file and reread it
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
Learn more about the HISTCONTROL variable here.
In a default Ubuntu install, in fact this command alone will do fine:
PROMPT_COMMAND="history -a; history -c; history -r"
Note that any new command from a different session will be available in your session after you "refreshed" the prompt: the history is updated as soon as a prompt is created.