ubuntu, updated

tmux cheat sheet

Keep sessions alive when SSH drops, split the terminal into panes, and work in several windows on one server.

Why tmux?

When your SSH connection drops, everything running in it dies: an upgrade, a big copy, a database import. tmux runs your shell on the server inside a session that keeps running when you disconnect. You reconnect and continue where you were. On top you get several windows and split panes in one SSH connection.

tmux is installed on Ubuntu Server by default.

The prefix key

Almost every tmux shortcut starts with the prefix: press Ctrl+B, release, then press the next key. Written below as Prefix + key.

Sessions

WhatCommand / keys
New session with a nametmux new -s work
Detach (session keeps running)Prefix d
List sessionstmux ls
Re-attachtmux attach -t work (or just tmux a)
Attach or create if missingtmux new -A -s work
Switch between sessionsPrefix s
Rename the sessionPrefix $
End a sessionexit in its last shell, or tmux kill-session -t work

Typical use: ssh srv01, tmux new -A -s work, start the long job, Prefix d, log out. Later: ssh srv01, tmux a.

Windows (like tabs)

WhatKeys
New windowPrefix c
Next / previous windowPrefix n / Prefix p
Go to window 0-9Prefix 0…9
List and pickPrefix w
Rename windowPrefix ,
Close windowexit or Prefix &

Panes (split screen)

WhatKeys
Split left/rightPrefix %
Split top/bottomPrefix "
Move between panesPrefix + arrow keys
Zoom a pane (toggle full size)Prefix z
ResizePrefix + Ctrl+arrow keys
Close paneexit or Prefix x
Same input to all panes (e.g. several SSH sessions)Prefix : then setw synchronize-panes

Scrolling and copying

WhatKeys
Scroll modePrefix [, then arrow keys / PgUp, q to leave
Search in scroll mode? (up) or / (down)
Use the mouse to scroll and selectadd set -g mouse on to ~/.tmux.conf

With mouse mode on, hold Shift (or Option on macOS) to select text for your computer’s clipboard.

~/.tmux.conf

set -g mouse on              # scroll and click with the mouse
set -g history-limit 50000   # longer scrollback
set -g base-index 1          # windows start at 1, not 0
bind | split-window -h       # Prefix | to split left/right
bind - split-window -v       # Prefix - to split top/bottom

Reload: tmux source-file ~/.tmux.conf.

Note: screen is the older tool that does the same. If a colleague left a screen session running: screen -ls, screen -r NAME, detach with Ctrl+A d.

§ home
~/knubertus/home/
1,1 Top