tmux
tmux is a modern terminal multiplexer — like GNU Screen, it runs persistent shell sessions that survive disconnection, but with a cleaner architecture, first-class window splitting, and a scriptable client/server design. Start work over SSH, detach, reconnect from another machine, and reattach to the same live session. Its killer trait beyond persistence is layout: effortless panes and windows that turn one terminal into a full workspace. This guide covers installation, the detach/reattach workflow, panes and windows, and a starter config.
tmux has a clean three-level hierarchy. Grasping it up front makes everything else obvious — it's the main thing that separates tmux from Screen's flatter design.
| Level | What it is |
|---|---|
| Session | The persistent top-level container that survives detach. You attach and detach from sessions |
| Window | Like a tab within a session — a full-screen workspace; a session holds many |
| Pane | A split within a window — multiple shells visible side by side at once |
tmux is packaged everywhere. Pick your platform.
bind -N notes) needs 3.1+, so check tmux -V if a config line is rejected. On minimal container images tmux isn't present by default — the one-liner adds it.Every tmux keyboard command starts with a prefix: Ctrl-b. Press the prefix, release, then the command key. Throughout this guide Ctrl-b d means "press Ctrl and b together, release, then press d."
| Notation | Means |
|---|---|
| Ctrl-b d | Prefix, then d — detach |
| Ctrl-b ? | Prefix, then ? — list every key binding |
| Ctrl-b : | Prefix, then : — open the tmux command prompt |
~/.tmux.conf — shown in section 08. This guide uses the default Ctrl-b throughout; translate to Ctrl-a if you remap.The reason to use tmux over SSH. Start a named session, run something long, detach, and it keeps running on the server without you.
You're inside tmux now, with a status bar at the bottom. Start a long job, then detach — the session and its processes stay alive on the server.
tmux attach -t deploy, and you're back exactly where you left off.| Command | Does |
|---|---|
| tmux new -s name | New named session |
| tmux ls | List sessions |
| tmux attach -t name | Reattach (short: tmux a -t name) |
| tmux new -As name | Attach if it exists, else create — the one-liner to always land in a session |
| tmux kill-session -t name | Kill one session |
| tmux kill-server | Kill every session at once |
tmux new -As main in your shell profile is a popular way to always drop into a persistent session on login.A session holds multiple windows — full-screen workspaces, shown as tabs in the status bar and numbered from 0.
| Keys | Action |
|---|---|
| Ctrl-b c | Create a new window |
| Ctrl-b n / p | Next / previous window |
| Ctrl-b 0…9 | Jump to window by number |
| Ctrl-b w | Interactive window/session tree picker |
| Ctrl-b , | Rename the current window |
| Ctrl-b & | Kill the current window (asks to confirm) |
| Ctrl-b f | Find a window by name |
Where tmux shines: split a window into panes and see several shells at once. Unlike Screen, a new pane opens a shell immediately — no separate "put a window in the region" step.
| Keys | Action |
|---|---|
| Ctrl-b % | Split vertically (left / right) |
| Ctrl-b " | Split horizontally (top / bottom) |
| Ctrl-b ←↑↓→ | Move focus between panes with arrow keys |
| Ctrl-b o | Cycle to the next pane |
| Ctrl-b z | Zoom the focused pane to full window (toggle) |
| Ctrl-b Space | Cycle through preset layouts |
| Ctrl-b { / } | Swap the focused pane left/up or right/down |
| Ctrl-b x | Kill the focused pane (asks to confirm) |
| Ctrl-b ! | Break the focused pane out into its own window |
tmux keeps its own scrollback per pane. Enter copy mode to scroll up and select text without a mouse.
| Keys | Action |
|---|---|
| Ctrl-b [ | Enter copy mode (then arrows / PgUp to scroll) |
| Space | Start selection (emacs keys); v in vi mode |
| Enter | Copy the selection and exit copy mode |
| Ctrl-b ] | Paste the copied buffer |
| q | Quit copy mode |
| Ctrl-b / | Search in copy mode (newer versions) |
set -g history-limit 50000 in your config so copy mode can reach further back. Note this only applies to panes created after the setting loads.tmux reads ~/.tmux.conf at server start. This is where it goes from useful to comfortable — a sensible starter below. Reload it live with Ctrl-b : then source-file ~/.tmux.conf.
set -g mouse on is the single most quality-of-life line: click to focus a pane, drag borders to resize, scroll naturally. For plugins, the tmux Plugin Manager (tpm) adds things like session persistence across reboots (tmux-resurrect) — worth exploring once the basics are second nature.| Keys / Command | Action |
|---|---|
| Ctrl-b d | Detach (leave running) |
| Ctrl-b c | New window |
| Ctrl-b n / p | Next / previous window |
| Ctrl-b , | Rename window |
| Ctrl-b % / " | Split vertical / horizontal |
| Ctrl-b arrows | Move between panes |
| Ctrl-b z | Zoom / unzoom pane |
| Ctrl-b [ | Scrollback / copy mode |
| Ctrl-b s / w | Session / window picker |
| Ctrl-b ? | List all key bindings |
| tmux new -s name | Start named session |
| tmux ls | List sessions |
| tmux a -t name | Reattach |
| tmux new -As name | Attach or create |
q to exit). To leave tmux, exit each pane and window until the session ends — that terminates it, unlike detaching, which leaves it running.