Score:0

Tmux History not preserved

yt flag

I am facing an issue in which the commands that I run inside the tmux terminal are not found when I exit that tmux session. Can, anyone please help?

tmux - using this command to run tmux session

echo "Hello" - using this command in tmux session

history - In this case echo "Hello" command is present.

exit - using this to exit the tmux session

history - running this command after exiting from tmux session

After running this I am not able to get echo "Hello" command that I used in tmux session.

Score:0
cn flag

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.

Kevin Martin avatar
yt flag
Thanks for helping me. It worked. I viewed various blogs earlier but wasn't able to understand them properly. Now, I understand why this was happening.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.