To view tmux command history, press Ctrl+b : and use the up/down arrows to cycle through previously used tmux commands. For shell command history within a tmux pane, use your shell's history feature (typically Ctrl+r or up arrow). To save tmux command history, add set -g history-file ~/.tmux_history
to your ~/.tmux.conf
file.
# View command history Ctrl+b :(then use up/down arrows) # Save command history to file set -g history-file ~/.tmux_history
tmux provides several types of history functionality that are useful for different purposes. Understanding these different history mechanisms can greatly improve your productivity.
There are three main types of history in tmux:
tmux maintains a history of commands entered in the command prompt (accessed with Ctrl+b :):
By default, tmux's command history is not saved between sessions. To enable persistent command history:
# Add to ~/.tmux.conf set -g history-file ~/.tmux_history
This configuration saves the command history to the specified file, making it available across tmux sessions and server restarts.
tmux keeps a record of terminal output for each pane, which you can access in copy mode:
The default scrollback size is 2000 lines. To increase it:
# Add to ~/.tmux.conf set -g history-limit 10000 # Increase to 10,000 lines
You can search through the scrollback history in copy mode:
To check your current mode or change it:
# Check current mode Ctrl+b :show-options -g mode-keys # Set to vi mode Ctrl+b :set-option -g mode-keys vi # Set to emacs mode Ctrl+b :set-option -g mode-keys emacs
Shell history within tmux panes is managed by your shell, not tmux:
history
command to view all historyTo enhance shell history in tmux, consider these shell configurations:
# For bash (add to ~/.bashrc) export HISTSIZE=10000 export HISTFILESIZE=10000 export HISTCONTROL=ignoredups:erasedups shopt -s histappend # For zsh (add to ~/.zshrc) HISTSIZE=10000 SAVEHIST=10000 setopt HIST_IGNORE_ALL_DUPS setopt HIST_SAVE_NO_DUPS setopt SHARE_HISTORY
There are several ways to save the scrollback history to a file:
# Capture the entire scrollback history of the current pane Ctrl+b :capture-pane -S - -E - Ctrl+b :save-buffer ~/tmux-history.txt # From the shell tmux capture-pane -pS - > ~/tmux-history.txt # Capture with formatting preserved tmux capture-pane -eS - | sed 's/\r$//' > ~/tmux-history-formatted.txt
The -S -
option captures from the start of history, while -E -
captures to the end.