tmux 3.8 cheat sheet

tmux cheat sheet: sessions, windows, panes and copy mode

tmux 3.8 puts every default keyboard shortcut behind the Ctrl-b prefix. Detach with Ctrl-b d, list sessions with tmux ls and reattach with tmux attach -t name. The 40 commands below cover sessions, windows, panes and copy mode, and since 3.8 the mouse works out of the box.

6 min readTerminals and remote servers

At a glance

  • Prefix: press Ctrl-b, release, then the key. Ctrl-b ? lists every binding.
  • Ctrl-b d detaches and leaves your programs running on the server.
  • Scroll back with Ctrl-b [ or the mouse wheel; each pane keeps 2,000 lines by default.
  • Mouse support is on by default since tmux 3.8. Debian 13 still ships 3.5a, where you add set -g mouse on.

How to read tmux key bindings

Every default keyboard shortcut in tmux starts with the prefix Ctrl-b: press Ctrl-b, let go of both keys, then press the next key. If you get stuck, Ctrl-b ? lists all bindings and Ctrl-b : opens the tmux command prompt. Every command also runs straight from your shell as tmux <command>.

The table lists the key and the shell command for each action, tested on tmux 3.8 and 3.5a.

ActionKeysCommand from the shell
New named sessiontmux new -s NAME
New session, detached, running a commandtmux new -d -s NAME 'cmd'
Attach if it exists, create it if nottmux new -A -s NAME
List sessionstmux ls
Attach to a sessiontmux attach -t NAME
DetachCtrl-b dtmux detach
Pick a session from a treeCtrl-b s
Rename the sessionCtrl-b $tmux rename-session -t OLD NEW
Previous or next sessionCtrl-b ( or Ctrl-b )
Type a command into a sessiontmux send-keys -t NAME 'cmd' Enter
Kill one sessiontmux kill-session -t NAME
Kill every sessiontmux kill-server
New windowCtrl-b ctmux new-window
Rename the windowCtrl-b ,tmux rename-window NAME
Next or previous windowCtrl-b n or Ctrl-b p
Window by numberCtrl-b 0 to Ctrl-b 9
Last windowCtrl-b l
Pick a window from a treeCtrl-b w
Kill the window (asks first)Ctrl-b &tmux kill-window
Split left and rightCtrl-b %tmux split-window -h
Split top and bottomCtrl-b "tmux split-window
Move to another paneCtrl-b then an arrow key
Next paneCtrl-b o
Last paneCtrl-b ;
Zoom the pane in and outCtrl-b ztmux resize-pane -Z
Turn the pane into a windowCtrl-b !tmux break-pane
Swap panesCtrl-b { or Ctrl-b }
Show pane numbersCtrl-b q
Cycle layoutsCtrl-b Space
Resize by 5 or by 1 cellCtrl-b Alt-arrow or Ctrl-b Ctrl-arrow
Kill the pane (asks first)Ctrl-b xtmux kill-pane
Enter copy modeCtrl-b [tmux copy-mode
Enter copy mode one page upCtrl-b PgUp
Leave copy modeq
Paste the last copyCtrl-b ]tmux paste-buffer
Save the whole scrollbacktmux capture-pane -p -S - > pane.txt
List key bindingsCtrl-b ?tmux list-keys
Command promptCtrl-b :
Reload the configtmux source-file ~/.tmux.conf
Show the versiontmux -V

Sessions

To start a named session, run tmux new -s NAME, or tmux new -A -s NAME to attach to NAME if it is already there and create it if it is not. tmux ls lists what is running and tmux attach -t NAME puts you back inside.

ls, new and attach are official aliases for list-sessions, new-session and attach-session. tmux also accepts any unambiguous prefix of a command name, which is why tmux a works for attach.

Inside a session, Ctrl-b d detaches and leaves everything running. When you are done, tmux kill-session -t NAME ends just that one and tmux kill-server ends all of them at once. The full workflow for long jobs is in the tmux detach and attach guide.

Windows and panes

Windows act like tabs inside a session: Ctrl-b c creates one, Ctrl-b , renames it and Ctrl-b & kills it after asking for confirmation. Ctrl-b n and Ctrl-b p move to the next and previous window, and Ctrl-b w lets you pick from a tree.

Panes split a single window into several terminals. Ctrl-b % splits it left and right, Ctrl-b " splits it top and bottom, and Ctrl-b x kills the active pane after asking first.

If a pane needs more room, Ctrl-b z zooms it to fill the whole window and zooms it back when you press it again. Ctrl-b ! breaks the pane out into its own window.

Copy mode and scrollback

Press Ctrl-b [ to enter copy mode, or Ctrl-b PgUp to enter it and scroll up one page right away; q leaves. The keys default to emacs style (Ctrl-Space starts a selection, Alt-w copies, Ctrl-s and Ctrl-r search) unless $VISUAL or $EDITOR contains "vi". Then you get vi style: Space starts a selection, Enter copies, / and ? search.

Once you have copied something, Ctrl-b ] pastes it into the pane. To dump a pane's whole scrollback to a file from the shell, run tmux capture-pane -p -S - > pane.txt. Every copy mode key is in the tmux scroll and copy mode guide.

Mouse support is on by default since tmux 3.8, so the wheel scrolls back through history, dragging selects and copies text, and clicking selects a pane. Your server might be older, since distribution packages lag behind: Debian 13 ships tmux 3.5a. Check with tmux -V and add set -g mouse on on 3.7 or older.

A starter ~/.tmux.conf

tmux reads ~/.tmux.conf or ~/.config/tmux/tmux.conf once, when the server starts. Reload it into a running server at any time with tmux source-file ~/.tmux.conf.

The default history-limit is 2,000 lines per pane. Since tmux 3.7, raising it also applies to panes that already exist, not only new ones. This config loads without errors on tmux 3.8 and 3.5a:

Text
# Mouse is on by default since tmux 3.8; this line is for older versions
set -g mouse on
set -g history-limit 50000
set -g base-index 1
setw -g pane-base-index 1
set -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
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind r source-file ~/.tmux.conf \; display "config reloaded"

With it, windows and panes count from 1, Ctrl-b | and Ctrl-b - split in the current directory, v and y select and copy like in vim, and Ctrl-b r reloads the file.

Keep a long job running after you log out

tmux new -d -s NAME 'command' starts a job without entering the session, but the session closes as soon as the command exits, taking the final output with it. Start a shell session and type the command into it instead, so the last lines stay readable:

Bash
tmux new -d -s train
tmux send-keys -t train 'python -u train.py' Enter
tmux ls
tmux attach -t train

Detaching keeps the process alive, but you still have to SSH back in and reattach every time you want to know whether the job finished or stalled.

Pass environment variables with tmux new -e NAME=value: a tmux server that is already running does not see variables you export later.

FAQ

What is the tmux prefix key and how do I change it?

Every default shortcut in tmux starts with Ctrl-b, which you press and release before the command key. To use Ctrl-a instead, put set -g prefix C-a, unbind C-b and bind C-a send-prefix in ~/.tmux.conf, then run tmux source-file ~/.tmux.conf.

How do I scroll up in tmux?

Press Ctrl-b PgUp to enter copy mode one page up, or press Ctrl-b [ and move with the arrow or page keys, then press q to leave. On tmux 3.8 the mouse wheel works too; on 3.7 and older add set -g mouse on first.

Is mouse support on by default in tmux?

Yes, starting with tmux 3.8 mouse support is enabled out of the box. Distribution packages often ship older versions (Debian 13 includes tmux 3.5a), so check with tmux -V and put set -g mouse on in ~/.tmux.conf on 3.7 or earlier.

How do I reload ~/.tmux.conf without restarting tmux?

Run tmux source-file ~/.tmux.conf from your shell, or press Ctrl-b : and run source-file ~/.tmux.conf at the tmux prompt. Since tmux 3.7, a new history-limit also reaches panes that already exist.

What is the difference between a session, a window and a pane?

A session is a set of windows that keeps running on the tmux server after you detach with Ctrl-b d. A window is a full-screen tab inside a session (Ctrl-b c), and panes are the terminal splits inside a window (Ctrl-b % and Ctrl-b ").

Check on long runs from your phone

Change one import and every tqdm bar prints a link you can open on any device. Get a Discord or Slack message when the run finishes, fails or stalls.

Get a live linkpip install tqdm-live

Sources