tmux
tmux commands: the cheat sheet you'll actually remember
The tmux commands worth memorising, grouped by what you are trying to do: sessions, windows, panes, copy mode and scripting.
Every tmux command is either a shell command (tmux something) or a key binding pressed after the
prefix, which is Ctrl-b unless you changed it. That single distinction explains most of
the confusion beginners have, so it is worth stating before the tables: tmux kill-session and
Ctrl-b then x are the same kind of thing, typed in two different places.
This is the reference I actually keep open, grouped by intent rather than alphabetically.
The prefix key, and why everything hangs off it
tmux reserves one chord so the other several hundred keys can still reach the program running
inside your pane. That chord is the prefix. Out of the box it is Ctrl-b.
You press the prefix, release it, then press the command key. Ctrl-b c is
"prefix, then c" — not a three-key chord.
Most people remap it to Ctrl-a because it is easier to reach:
unbind C-b
set -g prefix C-a
bind C-a send-prefixThat last line matters: it lets you send a literal Ctrl-a through to the shell (where it
means "start of line") by pressing it twice.
Reload without restarting
After editing ~/.tmux.conf, run tmux source-file ~/.tmux.conf, or bind it:
bind r source-file ~/.tmux.conf \; display "reloaded".
Session commands
A session is the top-level container. It survives your terminal closing, which is the entire reason tmux exists.
| Command | What it does |
|---|---|
| tmux | Start a new unnamed session |
| tmux new -s work | Start a new session called work |
| tmux ls | List sessions (long form: list-sessions) |
| tmux attach -t work | Attach to the session called work |
| tmux a | Attach to the most recent session |
| tmux switch -t api | Switch the current client to another session |
| tmux kill-session -t work | Kill one session |
| tmux kill-server | Kill every session on this server |
And the key bindings for the same operations, once you are already inside:
| Keys | What it does |
|---|---|
| prefix d | Detach — leave everything running |
| prefix s | Interactive session picker |
| prefix $ | Rename the current session |
| prefix ( / ) | Previous / next session |
The one to internalise is prefix d. Detaching is not quitting: your processes keep
running, and tmux attach puts you back exactly where you were —
attaching has its own sharp edges once two clients are involved.
Window commands
Windows are tabs inside a session.
| Keys | What it does |
|---|---|
| prefix c | Create a window |
| prefix , | Rename the current window |
| prefix n / p | Next / previous window |
| prefix 0-9 | Jump to window by number |
| prefix w | Interactive window picker |
| prefix f | Find a window by name |
| prefix & | Kill the current window |
Naming windows is the highest-value habit here. prefix , and typing api costs two seconds and
saves you from a status bar reading 0:zsh 1:zsh 2:zsh.
Pane commands
Panes are splits within a window.
| Keys | What it does |
|---|---|
| prefix % | Split vertically (side by side) |
| prefix " | Split horizontally (stacked) |
| prefix o | Cycle to the next pane |
| prefix ; | Toggle to the last-used pane |
| prefix arrow | Move to the pane in that direction |
| prefix z | Zoom the pane to fullscreen, press again to restore |
| prefix x | Kill the current pane |
| prefix { / } | Move the pane left / right in the layout |
| prefix space | Cycle through the preset layouts |
prefix z is the one people miss
Zoom is the single most useful pane binding. You can keep a four-pane layout and still read a full stack trace without touching the layout itself — zoom, read, zoom back.
The mnemonic for the splits is that % looks like a vertical divider and " looks like two stacked
marks. If that does not stick, rebind them to something that does — see
the tmux tutorial for a minimal config that sets these up from scratch:
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"The -c "#{pane_current_path}" part makes new panes open in the directory you were already in,
which is what you almost always want and is not the default.
Copy mode
Copy mode is how you scroll, search and select. Enter it with prefix [ and leave it with
q.
| Keys | What it does |
|---|---|
| prefix [ | Enter copy mode |
| / or ? | Search forward / backward |
| n / N | Next / previous match |
| space | Start selection (vi mode) |
| Enter | Copy selection and exit |
| prefix ] | Paste the buffer |
| q | Leave copy mode |
If those keys feel wrong, you are probably a vim user and tmux is in emacs mode. Fix it:
setw -g mode-keys vi
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send -X copy-selection-and-cancelCommands worth knowing for scripts
These are the ones that make tmux useful from a shell script or a dotfiles repo, and they are where the shell-command form earns its keep.
| Command | What it does |
|---|---|
| tmux new -d -s ci | Create a detached session without attaching |
| tmux send-keys -t ci 'npm test' Enter | Type a command into a pane |
| tmux capture-pane -p -t ci | Print a pane's contents to stdout |
| tmux list-panes -a -F '#{session_name}:#{window_index}' | Machine-readable pane list |
| tmux has-session -t ci 2>/dev/null | Exit 0 if the session exists — ideal for guards |
| tmux set-hook -g pane-died 'run "..."' | React to a pane's process dying |
capture-pane and has-session are the two that turn tmux from an interactive tool into
something you can automate around. A dev-environment bootstrap script is usually just
has-session || (new -d; send-keys; send-keys; ...).
The subset that covers 90% of real use
If you only memorise ten, memorise these:
tmux new -s name
prefix d
tmux attach -t name
prefix c
prefix ,
prefix % and prefix "
prefix arrow
prefix z
prefix [
prefix ?
That last one is the real cheat sheet. prefix ? lists every key binding your config
currently has, which is more accurate than any article — including this one — because it reflects
your actual ~/.tmux.conf.
Reading a session you are not sitting at
The commands above assume you are at the machine. The awkward case is the one where you started a long run, walked away, and want to know whether it finished.
tmux capture-pane -p over SSH works, and for a quick check it is fine —
running tmux over SSH has its own failure modes worth knowing. What it does not
do is tell you when something happened; you have to keep asking. If you would rather be told,
mtmux attaches to the tmux server you already run and serves the same session to a
browser, with a push notification when a pane goes quiet or a command exits.
Either way, the tmux commands stay exactly the same. Nothing above changes.
What is the default tmux prefix key?
Ctrl-b. You press and release it, then press the command key. Many people remap it to
Ctrl-a in ~/.tmux.conf because it is easier to reach.
How do I list all tmux commands and key bindings?
Press prefix ? inside tmux to list every current binding, or run
tmux list-commands in a shell for the full command set. The in-tmux listing is more
useful because it reflects your own config.
What is the difference between detaching and killing a tmux session?
Detaching (prefix d) leaves every process running and lets you reattach later with
tmux attach. Killing (tmux kill-session) terminates the session and
everything running inside it.
How do I scroll up in tmux?
Enter copy mode with prefix [, then scroll with the arrow keys or Page Up. Press
q to leave. With mode-keys vi set, / searches the scrollback.
Why do new tmux panes open in my home directory?
That is the default. Add -c "#{pane_current_path}" to your split bindings to make new panes
inherit the current pane's working directory instead.
Put this to work — mtmux attaches to the tmux server you already run.