Store contents of tmux pane to a file to keep the history or inspect recently executed commands.

Capture contents using terminal commands

Capture contents of the current pane to the capture-buffer.

$ tmux capture-pane -b temp-capture-buffer -S -

Store contents of the capture-buffer buffer to the ~/tmux.log file.

$ tmux save-buffer -b temp-capture-buffer ~/tmux.log

Delete capture-buffer buffer.

$ tmux delete-buffer -b capture-buffer

Capture contents using the tmux command

Define prefix-S command to capture contents to ~/tmux.log.

bind-key S capture-pane -b temp-capture-buffer -S - \; save-buffer -b temp-capture-buffer ~/tmux.log \; delete-buffer -b capture-buffer

Define the prefix-Meta-S command to capture contents to a specific file.

bind-key M-S command-prompt -I "~/tmux.log" -p "Store current pane contents to file:" "capture-pane -b temp-capture-buffer -S -; save-buffer -b temp-capture-buffer %1; delete-buffer -b capture-buffer"

Store these commands inside ~/.tmux.conf configuration file.

Reload tmux environment.

$ tmux source-file ~/.tmux.conf

Capture contents using the tmux plugin

The third method is to use tmux-logging, easy logging, and screen capturing for Tmux.

Clone tmux-plugins/tmux-logging repository.

$ git clone https://github.com/tmux-plugins/tmux-logging ~/.tmux/tmux-logging

Include downloaded plugin in your ~/.tmux.conf configuration.

run-shell ~/.tmux/tmux-logging/logging.tmux

Reload tmux environment.

$ tmux source-file ~/.tmux.conf

Use prefix + alt + shift + p to capture the current pane contents.