How do I see the history of the commands I have run in tmux?

39,252

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

Share:
39,252

Related videos on Youtube

Chris Magnuson
Author by

Chris Magnuson

Updated on September 18, 2022

Comments

  • Chris Magnuson
    Chris Magnuson over 1 year

    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?

    • Radu Rădeanu
      Radu Rădeanu over 10 years
      So, you want to see the history of the commands that you ran inside tmux in your bash terminal?
    • demure
      demure over 10 years
      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.
    • Chris Magnuson
      Chris Magnuson over 10 years
      @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.
    • Chris Magnuson
      Chris Magnuson over 10 years
      @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.
  • Chris Magnuson
    Chris Magnuson over 10 years
    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?
  • Radu Rădeanu
    Radu Rădeanu over 10 years
    @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.
  • avp
    avp about 7 years
    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.
  • Robert Bain
    Robert Bain about 4 years
    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.