I am running 12.04 server and when I type history in bash I see most of the commands I have entered into bash but I don't see the commands I have entered when in a tmux session.

How do I see the history of the commands I have run inside a tmux session on Ubuntu 12.04 server after I have ended the session?

  • So, you want to see the history of the commands that you ran inside tmux in your bash terminal? Aug 31, 2013 at 17:50
  • If you are referring to the history of bash inside of tmux, and said shell is still running, you will have to add some settings to your ~/.bashrc and ~/.bash_login to make history append to the file while running.
    – demure
    Aug 31, 2013 at 22:03
  • @demure I am referring to the history of a bash shell that was inside tmux but tmux and the bash shell that was running in tmux are both no longer running. Aug 31, 2013 at 23:31
  • @RaduRădeanu When I type tmux at bash and get a new bash shell, run ls and then exit, I am now back at the first bash shell and the history command shows that I ran tmux but not that I ran ls. Aug 31, 2013 at 23:33

2 Answers 2


You have to preserve bash history in multiple bash shells. To do this, be sure that you have the following lines in your ~/.bashrc file:

# avoid duplicates..
export HISTCONTROL=ignoredups:erasedups

# append history entries..
shopt -s histappend

# After each command, save and reload history
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

Source: https://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows

  • 2
    I tired this out on 12.04 Ubuntu server and now each time I type the history command my history number increments by 40. I typed history in the shell three times and my last command number went from 1305 to 1345 to 1385 to 1425 and so on. Why is this happening? Sep 7, 2013 at 20:33
  • 2
    @ChrisMagnuson This doesn't happen at me. Anyway, this is a different question toward your original question. So, don't hesitate to use Ask Question button. Sep 7, 2013 at 20:45
  • on zsh+tmux it looks fine: ': 1490862052:0;ls #1 : 1490862057:0;ls #2 : 1490862068:0;tail ~/.zsh_history : 1490862083:0;ls #3 : 1490862087:0;tail ~/.zsh_history #2' given that each command is executed in different pane.
    – avp
    Mar 30, 2017 at 8:23
  • This works with multiple panes and sessions. Sometimes the latest cmd will not show, but just run some other cmd (e.g. echo "lol") and try again. It should work now. This is a near perfect solution that takes just seconds to implement. Apr 25, 2020 at 13:16

To enable bash history in tmux, run bash on tmux startup. To do this, put this line into your .tmux.conf file:

set-option -g default-command bash
  • Wish this worked, but it didn't for me...
    – Alex K
    Apr 16, 2023 at 17:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .