At a glance
- Prefix: press
Ctrl-b, release, then the key.Ctrl-b ?lists every binding. Ctrl-b ddetaches 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.
| Action | Keys | Command from the shell |
|---|---|---|
| New named session | tmux new -s NAME | |
| New session, detached, running a command | tmux new -d -s NAME 'cmd' | |
| Attach if it exists, create it if not | tmux new -A -s NAME | |
| List sessions | tmux ls | |
| Attach to a session | tmux attach -t NAME | |
| Detach | Ctrl-b d | tmux detach |
| Pick a session from a tree | Ctrl-b s | |
| Rename the session | Ctrl-b $ | tmux rename-session -t OLD NEW |
| Previous or next session | Ctrl-b ( or Ctrl-b ) | |
| Type a command into a session | tmux send-keys -t NAME 'cmd' Enter | |
| Kill one session | tmux kill-session -t NAME | |
| Kill every session | tmux kill-server | |
| New window | Ctrl-b c | tmux new-window |
| Rename the window | Ctrl-b , | tmux rename-window NAME |
| Next or previous window | Ctrl-b n or Ctrl-b p | |
| Window by number | Ctrl-b 0 to Ctrl-b 9 | |
| Last window | Ctrl-b l | |
| Pick a window from a tree | Ctrl-b w | |
| Kill the window (asks first) | Ctrl-b & | tmux kill-window |
| Split left and right | Ctrl-b % | tmux split-window -h |
| Split top and bottom | Ctrl-b " | tmux split-window |
| Move to another pane | Ctrl-b then an arrow key | |
| Next pane | Ctrl-b o | |
| Last pane | Ctrl-b ; | |
| Zoom the pane in and out | Ctrl-b z | tmux resize-pane -Z |
| Turn the pane into a window | Ctrl-b ! | tmux break-pane |
| Swap panes | Ctrl-b { or Ctrl-b } | |
| Show pane numbers | Ctrl-b q | |
| Cycle layouts | Ctrl-b Space | |
| Resize by 5 or by 1 cell | Ctrl-b Alt-arrow or Ctrl-b Ctrl-arrow | |
| Kill the pane (asks first) | Ctrl-b x | tmux kill-pane |
| Enter copy mode | Ctrl-b [ | tmux copy-mode |
| Enter copy mode one page up | Ctrl-b PgUp | |
| Leave copy mode | q | |
| Paste the last copy | Ctrl-b ] | tmux paste-buffer |
| Save the whole scrollback | tmux capture-pane -p -S - > pane.txt | |
| List key bindings | Ctrl-b ? | tmux list-keys |
| Command prompt | Ctrl-b : | |
| Reload the config | tmux source-file ~/.tmux.conf | |
| Show the version | tmux -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:
# 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:
tmux new -d -s train
tmux send-keys -t train 'python -u train.py' Enter
tmux ls
tmux attach -t trainDetaching 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.
pip install tqdm-liveSources
- tmux 3.8 release on GitHub github.com
- tmux CHANGES file github.com
- tmux manual page man.openbsd.org
- tmux wiki: Getting Started github.com
- Debian 13 tmux package packages.debian.org