tmux is a terminal multiplexer: one terminal window can hold many shell sessions at once, and those sessions keep running even when you disconnect.
Think of it as a window manager that lives inside your terminal:
The killer feature is the detach/reattach model. Your programs run inside
the tmux server, not inside your terminal. Close the laptop, drop the VPN,
get kicked off SSH — the server keeps everything running, and you pick up
exactly where you left off with tmux attach.
tmux # start a new unnamed session
tmux new -s work # start a new session named "work"
tmux ls # list running sessions
tmux attach # reattach to the most recent session
tmux attach -t work # reattach to a session by name
tmux kill-session -t work # end a session and everything in it
Every tmux keyboard command starts with a prefix: Ctrl+b by default.
Press and release the prefix, then press the command key. So “split the
window” is: hold Ctrl, press b, release both, press %.
Written shorthand throughout this guide: prefix % means Ctrl+b then %.
# on the server
tmux new -s etl # 1. create a workspace for the task
# ... start a long-running job in one pane,
# tail its log in another (prefix % to split) ...
# prefix d # 2. detach — the job keeps running
exit # 3. log out, go home
# later, from anywhere
ssh the-server
tmux attach -t etl # 4. everything is still there, still running
tmux reads ~/.tmux.conf at server start. A minimal, widely useful config:
set -g mouse on # click to select panes, scroll to scroll
set -g history-limit 50000 # keep plenty of scrollback
set -g base-index 1 # number windows from 1 (0 is far from the keys)
set -g status-interval 5 # refresh the status bar more often
Reload it into a running server with tmux source-file ~/.tmux.conf
(or prefix : then source-file ~/.tmux.conf).
This repo’s
scripts/terminal-bootstrap.shinstalls a managed, 8-color-safe.tmux.confblock (mouse on, 50k scrollback, styled status bar) suitable for restricted HTML5-gateway terminals. The minifiedterminal-bootstrap-min.shvariant deliberately leaves tmux alone.
nohup ... & and hunting
for the output file.tmux new-session ... \; split-window ...), so a whole project
layout can be one command.tmux new -s api-debug). tmux ls output full of
0: 1 windows... helps nobody.set -g mouse on). Clicking panes and scrolling
with the wheel removes most of the learning curve.prefix ,). A status bar reading
logs | psql | editor beats bash | bash | bash.tmux attach -d if the layout looks squashed — it detaches other
(smaller) clients that are forcing the screen size down.prefix z makes the current pane
full-screen; press it again to restore the split.prefix [ then
PgUp/arrows (or just wheel-scroll with mouse mode on). q to leave.history-limit before windows are created — it isn’t retroactive.exit vs detach. Typing exit in the last pane of the last window
kills the session. To leave things running, detach (prefix d).Ctrl+b Ctrl+b d sends the detach to the inner tmux.prefix : then
setw synchronize-panes on types into every pane at once — handy for
a handful of servers, dangerous if you forget it’s on.All of these are prefix (Ctrl+b) followed by the key shown.
| Keys | Action |
|---|---|
d |
Detach — leave everything running |
s |
Pick a session from a list |
$ |
Rename the current session |
( / ) |
Previous / next session |
| Keys | Action |
|---|---|
c |
Create a new window |
, |
Rename the current window |
n / p |
Next / previous window |
0–9 |
Jump to window by number |
w |
Pick a window from a list |
& |
Kill the current window (confirms first) |
| Keys | Action |
|---|---|
% |
Split left/right |
" |
Split top/bottom |
← → ↑ ↓ |
Move between panes |
o |
Cycle to the next pane |
z |
Zoom pane to full screen (toggle) |
x |
Kill the current pane (confirms first) |
{ / } |
Swap pane with the previous / next one |
Space |
Cycle through preset layouts |
q |
Show pane numbers (press a number to jump) |
! |
Break the pane out into its own window |
| Keys | Action |
|---|---|
[ |
Enter copy mode (scroll with arrows / PgUp) |
] |
Paste the tmux buffer |
: |
Command prompt (type any tmux command) |
t |
Big clock (surprisingly useful for screenshares) |
? |
List every key binding |
The copy-mode keys depend on the mode-keys option. The default is
emacs. tmux uses vi only when $VISUAL or $EDITOR contains vi.
mode-keys |
Start a selection | Copy the selection | Quit |
|---|---|---|---|
emacs (default) |
Ctrl+Space |
Alt+w or Ctrl+w |
q or Escape |
vi (setw -g mode-keys vi) |
Space |
Enter |
q |
In vi mode, v toggles a rectangle selection. y has no default
binding. To get Vim-style v / y, add your own bindings to
copy-mode-vi.
The everyday “save” is simply detaching (prefix d). The session — running
processes, window layout, scrollback — lives on inside the tmux server until
the machine reboots or you kill the session. tmux attach -t name is the
matching “load”.
prefix [). Start a selection and copy
it with the keys for your mode-keys setting (see “Copy mode & misc”).
Paste into any pane with prefix ].Dump a pane’s scrollback to a file:
tmux capture-pane -t etl -pS -50000 > pane-log.txt
-S -50000 reaches back that many lines into history; -p prints to
stdout so you can redirect it.
prefix : then pipe-pane -o 'cat >> ~/pane.log'
appends everything that appears in the pane to a file (run it again to
stop). Start it before the interesting output happens.A plain tmux session does not survive a server reboot — the tmux server is just a process. Two plugins fix that:
prefix Ctrl+s saves every session/window/pane (and optionally running
programs); prefix Ctrl+r restores them after a reboot.Both install in one line each via tpm, the tmux plugin manager.
For layouts you rebuild often, script them instead of preserving them:
#!/usr/bin/env bash
tmux new-session -d -s etl -n job
tmux split-window -h -t etl:job # log tail beside the job
tmux send-keys -t etl:job.0 'cd ~/etl' Enter
tmux send-keys -t etl:job.1 'tail -f ~/etl/run.log' Enter
tmux attach -t etl
Run the script and the workspace exists; no state to back up, nothing to lose. Tools like tmuxinator do the same thing declaratively from YAML if you prefer config over script.