I think we know that screen is officially old news and most modern Linux systems switched to tmux as the recommended multiplexer with RHEL 8. Recently I had a discussion amongst my DBA gang for tmux migration and decided to write this. If you’re still using screen, now’s the time to upgrade: tmux is fun! (I know I’m late in the party but better late than never)
This tmux cheat sheet combins session management, logging, reloading config, and scrolling commands in a quick reference format. You can also configure the tmux commands identical to screen by config file (using Ctrl-a).
Tmux Demo Session
Tmux Session Management
Action | Command / Shortcut |
---|---|
Start new session | tmux new -s session_name |
List sessions | tmux ls |
Attach session | tmux attach -t session_name tmux a (last session) |
Detach session | Ctrl + b then d |
Kill session | tmux kill-session -t session_name (or connect session and exit) |
Attach a session | tmux attach-session -t session_name |
Forcefully take-over a session | tmux attach-session -d -t session_name |
Tmux Logging
Action | Command |
---|---|
Start logging current pane | tmux pipe-pane -o 'cat >> ~/tmux.log' |
Stop logging | tmux pipe-pane |
Tmux Reload Config
Action | Command / Shortcut |
---|---|
Reload config | tmux source-file ~/.tmux.conf (from shell) |
Reload config (inside tmux) | Ctrl + b then : then source-file ~/.tmux.conf |
Tmux Scrolling / Copy Mode
Action | Command / Shortcut |
---|---|
Enter copy/scroll mode | Ctrl + b then [ |
Scroll up/down | Arrow keys, Page Up / Page Down |
Exit copy mode | q or Esc |
Enable mouse scrolling | Add “set -g mouse on ” to ~/.tmux.conf and reload |
Tmux Key Bindings
Action | Shortcut |
---|---|
Detach session | Ctrl + b then d |
List sessions | Ctrl + b then s |
Rename session | Ctrl + b then $ |
New window | Ctrl + b then c |
Split horizontally | Ctrl + b then " |
Split vertically | Ctrl + b then % |
Navigate panes | Ctrl + b then Arrow keys |
Configuration customization
You can customize using tmux.conf configuration file further with additional bind keys for your workflow!
If you’re habituated to screen command you can change the default shortcut command from “Ctrl-b” to “Ctrl-a” using configuration. There’s more power in the configuration, have a look.
tmux.conf: Key Settings & Bindings
Action | Command / Config Line |
---|---|
Enable default pane logging to timestamped file | set-option -g default-command ‘tmux pipe-pane -o “cat >>~/tmxlogs/tmx-#{session_name}-\`date +%Y%m%dT%H%M%S\`.log”; /bin/bash -l’ |
Enable mouse support | set -g mouse on |
Increase scrollback/history buffer size | set -g history-limit 10000 |
Reload tmux config shortcut (prefix + r) | bind r source-file ~/.tmux.conf \; display-message "Config reloaded!" |
Unbind default prefix key (Ctrl+b) | unbind C-b |
Set prefix key to Ctrl+a (Screen style) | set-option -g prefix C-a |
Reload config with prefix + Shift + R | bind-key R source-file ~/.tmux.conf \; display-message "Config reloaded!" |
Sample ~/.tmux.conf
You can use the following configuration:
# vim ~/.tmux.conf
# Enable default logging
set-option -g default-command 'tmux pipe-pane -o "cat >>~/tmxlogs/tmx-#{session_name}-\`date +%Y%m%dT%H%M%S\`.log"; /bin/bash -l'
# Enable mouse support for scrolling and pane selection
set -g mouse on
# Increase scrollback / log history buffer size
set -g history-limit 10000
# Reload config shortcut - Ctrl+b, R to reload config changes
bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"
# Screen compatible commands settings
unbind C-b # Unbind default prefix
set-option -g prefix C-a # Set prefix to Ctrl+a (same as screen)
To make use of configuration changes for the first time you need to run
tmux source ~/.tmux.conf
Once you have added “Reload config shortcut” you just need to press: Ctrl-a, r to reload the changes.