Skip to content

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.

Ivo Hartupdated Jul 26, 20267 min read

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:

~/.tmux.conf
unbind C-b
set -g prefix C-a
bind C-a send-prefix

That 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.

CommandWhat it does
tmuxStart a new unnamed session
tmux new -s workStart a new session called work
tmux lsList sessions (long form: list-sessions)
tmux attach -t workAttach to the session called work
tmux aAttach to the most recent session
tmux switch -t apiSwitch the current client to another session
tmux kill-session -t workKill one session
tmux kill-serverKill every session on this server

And the key bindings for the same operations, once you are already inside:

KeysWhat it does
prefix dDetach — leave everything running
prefix sInteractive 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.

mbp — tmux
[object Object],[object Object],[object Object]

Window commands

Windows are tabs inside a session.

KeysWhat it does
prefix cCreate a window
prefix ,Rename the current window
prefix n / pNext / previous window
prefix 0-9Jump to window by number
prefix wInteractive window picker
prefix fFind 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.

KeysWhat it does
prefix %Split vertically (side by side)
prefix "Split horizontally (stacked)
prefix oCycle to the next pane
prefix ; Toggle to the last-used pane
prefix arrowMove to the pane in that direction
prefix zZoom the pane to fullscreen, press again to restore
prefix xKill the current pane
prefix { / }Move the pane left / right in the layout
prefix spaceCycle 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:

~/.tmux.conf
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.

KeysWhat it does
prefix [Enter copy mode
/ or ?Search forward / backward
n / NNext / previous match
spaceStart selection (vi mode)
EnterCopy selection and exit
prefix ]Paste the buffer
qLeave copy mode

If those keys feel wrong, you are probably a vim user and tmux is in emacs mode. Fix it:

~/.tmux.conf
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-cancel

Commands 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.

CommandWhat it does
tmux new -d -s ciCreate a detached session without attaching
tmux send-keys -t ci 'npm test' EnterType a command into a pane
tmux capture-pane -p -t ciPrint 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/nullExit 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; ...).

~/bin/dev — idempotent session bootstrap
[object Object],[object Object]

The subset that covers 90% of real use

If you only memorise ten, memorise these:

tmux new -s name

Start a named session.

prefix d

Detach and leave it running.

tmux attach -t name

Come back to it.

prefix c

New window.

prefix ,

Name that window.

prefix % and prefix "

Split into panes.

prefix arrow

Move between panes.

prefix z

Zoom a pane and unzoom it.

prefix [

Scroll and search the output.

prefix ?

List every binding, when you forget one.

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.

Related reading