To log tmux pane output to a file, use the pipe-pane
command with a shell command that redirects to a file. Press Ctrl+b : then type pipe-pane -o "cat >> ~/tmux-log.txt"
. This logs all output from the current pane to the file. Use pipe-pane
without arguments to stop logging. For more control, use the tmux-logging
plugin, which adds key bindings for logging, screen capture, and save complete history functionality.
# Start logging current pane Ctrl+b :pipe-pane -o "cat >> ~/tmux-log.txt" # Stop logging Ctrl+b :pipe-pane # Log with timestamp in filename Ctrl+b :pipe-pane -o "cat >> ~/tmux-$(date +%Y%m%d-%H%M%S).log"
tmux provides several ways to log the output of panes, which is useful for recording terminal sessions, capturing command outputs, and maintaining history of your work.
The pipe-pane
command is tmux's built-in mechanism for logging pane output. It pipes all output that would appear in the pane to a shell command:
# Basic logging to a file tmux pipe-pane -o "cat >> ~/tmux-log.txt" # Log with timestamp in filename tmux pipe-pane -o "cat >> ~/tmux-$(date +%Y%m%d-%H%M%S).log" # Only log stdout (no stderr) tmux pipe-pane -o "cat > ~/tmux-stdout.log" # Only log stderr (no stdout) tmux pipe-pane -o "cat > /dev/null 2>> ~/tmux-stderr.log"
Options for the pipe-pane
command:
-o
- Only pipes new output, not existing content-I
- Also pipes input to the panepipe-pane
stops any active loggingTo log a different pane than the current one, specify the target:
# Log a specific pane by index tmux pipe-pane -t 0:1.2 -o "cat >> ~/pane-1-2.log" # Log a specific session:window.pane tmux pipe-pane -t mysession:2.1 -o "cat >> ~/specific-pane.log"
For more advanced logging features, the tmux-logging
plugin offers a comprehensive solution:
# Install with TPM (Tmux Plugin Manager) # Add to ~/.tmux.conf set -g @plugin 'tmux-plugins/tmux-logging' # If using TPM, press Ctrl+b I to install
The tmux-logging plugin provides several useful key bindings:
~/tmux-logging
) For even more control, you can use pipe-pane
with external tools:
# Log with timestamps before each line using 'ts' (moreutils package) tmux pipe-pane -o "cat | ts '%Y-%m-%d %H:%M:%S' >> ~/tmux-timestamped.log" # Log with rotated log files using 'rotatelogs' (apache2-utils package) tmux pipe-pane -o "cat | rotatelogs -n 5 ~/tmux-log.%i.txt 10M" # Log with compression tmux pipe-pane -o "cat | gzip > ~/tmux-log.gz"