| Tested on | Ubuntu 25.04 (Plucky Puffin) |
|---|---|
| Package | tmux 3.5a |
| Applies to | Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Oracle Linux, CentOS Stream, Fedora, Arch Linux, SUSE, openSUSE, Alpine |
| Privilege | Regular user; sudo or root only for package installation or commands that genuinely require elevated privileges |
| Man page | tmux(1) |
| Scope | tmux is a terminal multiplexer that keeps shell sessions running in the background, splits one screen into panes and windows, and reconnects after SSH drops. Default prefix is Ctrl+b. |
| Related guides | Complete tmux commands tutorial tmux configuration guide ssh sudo Linux commands |
tmux — quick reference
Default prefix key: Ctrl+b (press and release, then the binding key). Run tmux list-keys -T prefix on your host to see local bindings.
Client startup
Flags passed when you launch the tmux binary from the shell.
| When to use | Command |
|---|---|
| Print the installed tmux version | tmux -V |
| Enable verbose client/server logging to the current directory | tmux -v |
| Force 256-colour terminal features | tmux -2 |
| Start in control mode (for scripts and integrations) | tmux -C |
| Run a command with tmux's default shell (compatibility; not a new pane) | tmux -c 'command' |
Run the tmux server in the foreground (exit-empty off; no subcommand) |
tmux -D |
| Load an alternate config when a new server starts | tmux -f /path/to/tmux.conf |
| Use a named socket so multiple independent servers can run | tmux -L socket-name |
Use a full path for the server socket (ignores -L) |
tmux -S /path/to/socket |
| Set terminal features for this client (comma-separated list) | tmux -T 256 |
| Write UTF-8 to the terminal even when locale is not UTF-8 | tmux -u |
| Compatibility flag for login-shell use; currently has no effect | tmux -l |
| Do not start the server even if the subcommand normally would | tmux -N |
Sessions
Create, list, attach to, and tear down persistent session groups. A pane normally closes when its command exits — -d only creates the session detached; it does not keep the pane open afterward. If the command is the last pane in the session, the session (and usually the server) exit when it finishes. Use remain-on-exit only when you specifically want an exited pane retained for inspection.
| When to use | Command |
|---|---|
| Start a new session in the foreground | tmuxtmux newtmux new-session |
| Start a detached session you can attach to later | tmux new -d -s NAME |
| Name the session at creation time | tmux new -s NAME |
| Set the first window name when creating a session | tmux new -s NAME -n winname |
| Start in a specific directory | tmux new -s NAME -c /path/to/dir |
| Run a command in a detached session | tmux new -d -s NAME 'command' |
| Run a command, then open a shell in the same pane | tmux new -d -s NAME 'command; exec "$SHELL"' |
Print session details with a format string (-P prints to stdout) |
tmux new -d -P -F '#{session_name}' -s NAME |
| List running sessions | tmux lstmux list-sessions |
| Check whether a session exists (exit 0 if yes) | tmux has-session -t NAME |
| Attach to the most recently used session | tmux attachtmux a |
| Attach to a named session | tmux attach -t NAME |
| Attach and force other clients off the same session | tmux attach -d -t NAME |
Detach the client you are in (same as prefix d) |
tmux detach |
| Rename a session | tmux rename-session -t OLD NEW |
| Kill one session | tmux kill-session -t NAME |
| Kill every session except the target | tmux kill-session -a -t NAME |
| Kill all sessions and stop the server | tmux kill-server |
Windows
Each session holds one or more full-screen windows; only one window is visible at a time.
| When to use | Command |
|---|---|
| Open a new window in the current or named session | tmux new-windowtmux neww -t SESSION: |
| Name the window at creation | tmux new-window -n NAME |
| List windows in a session | tmux list-windows -t SESSION |
| Jump to window index 0–9 | tmux select-window -t SESSION:0 |
| Select the next or previous window | tmux next-windowtmux previous-window |
| Rename the active window | tmux rename-window NEWNAME |
| Close a window | tmux kill-window -t SESSION:INDEX |
| Close every window except the target | tmux kill-window -a -t SESSION:INDEX |
| Move a window to another session or index | tmux move-window -s SESSION:IDX -t SESSION:IDX |
Panes
Split the visible window into side-by-side or stacked terminals.
| When to use | Command |
|---|---|
| Split the current pane top/bottom | tmux split-window |
| Split the current pane left/right | tmux split-window -h |
| Split with a fixed size (lines or columns) | tmux split-window -l 20 |
| Start the new pane in a specific directory | tmux split-window -c /path/to/dir |
| List panes in a window | tmux list-panes -t SESSION:WIN |
| Select the next or previous pane | tmux select-pane -t :.+tmux select-pane -t :.- |
| Select pane by index in the window | tmux select-pane -t SESSION:WIN.INDEX |
| Zoom the active pane to full window (toggle) | tmux resize-pane -Z |
| Swap two panes | tmux swap-pane -s SRC -t DST |
| Turn a pane into its own window | tmux break-pane |
| Kill the active pane | tmux kill-pane |
| Kill all panes except the target | tmux kill-pane -a -t SESSION:WIN.INDEX |
| Capture visible pane text to stdout | tmux capture-pane -p |
| Send keystrokes to a pane | tmux send-keys -t TARGET 'command' Enter |
Key bindings (default prefix Ctrl+b)
Press Ctrl+b, release, then the key shown. These match tmux 3.5a defaults (tmux list-keys -T prefix).
| When to use | Binding |
|---|---|
| Detach from the session (processes keep running) | Ctrl+b d |
| Rename the current session | Ctrl+b $ |
| Switch to previous / next session | Ctrl+b ( / Ctrl+b ) |
| Pick a session from an interactive tree | Ctrl+b s |
| Create a new window | Ctrl+b c |
| Rename the current window | Ctrl+b , |
| Next / previous window | Ctrl+b n / Ctrl+b p |
| Jump to window 0–9 | Ctrl+b 0 … Ctrl+b 9 |
| Pick a window from an interactive tree | Ctrl+b w |
| Close the current window (prompts to confirm) | Ctrl+b & |
| Split pane top/bottom | Ctrl+b " |
| Split pane left/right | Ctrl+b % |
| Move to the next pane | Ctrl+b o |
| Toggle between the last two panes | Ctrl+b ; |
| Kill the current pane (prompts to confirm) | Ctrl+b x |
| Zoom the active pane | Ctrl+b z |
| Select the pane above, below, left, or right | Ctrl+b Up/Down/Left/Right |
| Resize the pane by one cell | Ctrl+b Ctrl+Up/Down/Left/Right |
| Resize the pane by five cells | Ctrl+b Alt+Up/Down/Left/Right |
| Rotate pane positions | Ctrl+b Ctrl+o |
| Cycle through pane layouts | Ctrl+b Space |
| Turn pane into a new window | Ctrl+b ! |
| Enter copy (scroll) mode | Ctrl+b [ |
| Paste from tmux buffer | Ctrl+b ] |
| Choose a paste buffer | Ctrl+b = |
Open the command prompt (: commands) |
Ctrl+b : |
| List all key bindings with descriptions | Ctrl+b ? |
Copy mode keys
Bindings depend on mode-keys (Emacs or vi). Check the active mode:
tmux show-options -gw mode-keysActive after Ctrl+b [ (copy mode). The man page defines separate Emacs and vi tables.
| Action | Emacs mode | vi mode |
|---|---|---|
| Move cursor | Arrow keys | h, j, k, l |
| Start selection | Ctrl+Space |
Space |
| Copy selection and exit | Alt+w |
Enter |
| Search backward | Ctrl+r |
? |
| Search forward | Ctrl+s |
/ |
| Exit copy mode | Escape |
q |
| Page up / page down | PgUp / PgDn |
Ctrl+b / Ctrl+f |
Outside copy mode, Ctrl+b PgUp enters copy mode and scrolls one page up (default prefix binding).
Buffers, clients, and configuration
| When to use | Command |
|---|---|
| List paste buffers | tmux list-buffers |
| Save a buffer to a file | tmux save-buffer -b buffer-name /path/file |
| Load a file into a buffer | tmux load-buffer /path/file |
| Delete a buffer | tmux delete-buffer -b buffer-name |
| List clients attached to sessions | tmux list-clients |
| Reload config without restarting tmux | tmux source-file ~/.tmux.conf |
| Show an option value | tmux show-options -g prefix |
| Set an option globally | tmux set-option -g mouse on |
| Display a formatted message | tmux display-message -p '#{session_name}' |
tmux — command syntax
Synopsis from the tmux 3.5a man page on Ubuntu 25.04:
tmux [-2CDlNuVv] [-c shell-command] [-f file] [-L socket-name]
[-S socket-path] [-T features] [command [flags]]Inside a running session, many actions use the prefix (default Ctrl+b) plus a single key, or the command prompt (Ctrl+b :) with tmux subcommands such as split-window.
Run tmux as the user who should own the sessions. sudo tmux creates a separate root-owned server and sessions your normal user will not see. Each user normally has an independent tmux server and socket under /tmp/tmux-UID or $TMUX_TMPDIR.
The tmux server keeps sessions, windows, panes, and their terminal state in memory. Clients communicate with that server through a Unix socket. Sessions survive SSH disconnects and client detaches; they do not survive the server exiting or a host reboot unless an external restoration tool is used. -f loads a config when a new server starts — use source-file to reload a running server. The system configuration file may still be read before ~/.tmux.conf.
tmux — command examples
Essential Create a named detached session and list it
Start work on a remote host without tying it to your current SSH window. A detached session keeps running after you log out.
Run the command:
tmux new -d -s work
tmux lsSample output:
work: 1 windows (created Wed Jul 1 14:18:30 2026)The session name (work) is what you pass to tmux attach -t work when you reconnect.
Essential Reattach to a running session
After SSH drops or you detached with Ctrl+b d, attach to pick up where you left off.
Run the command:
tmux attach -t workSample output (when run from a real terminal):
[exits into the tmux session — status bar shows session name and window list]If no session exists, tmux prints can't find session: work. Create it first with tmux new -s work or check names with tmux ls.
Essential Split a window into multiple panes from the shell
You can split panes with key bindings inside tmux, or drive layout from scripts using split-window.
Run the commands:
tmux new -d -s demo -n shell 'sleep 600'
tmux split-window -t demo:shell -h
tmux split-window -t demo:shell.1 -v
tmux list-panes -t demo:shell -F '#{pane_index} #{pane_width}x#{pane_height}'Sample output:
0 40x24
1 39x12
2 39x11Pane 0 is on the left; panes 1 and 2 stack on the right. Sessions started with 'sleep 600' exist only until sleep ends or you kill the session. Clean up with tmux kill-session -t demo when finished.
Common Add windows and inspect the layout
Windows are full-screen tabs inside one session — useful when one tab runs an app and another tails logs.
Run the commands:
tmux new -d -s ops -n app 'sleep 600'
tmux new-window -t ops -n logs 'sleep 600'
tmux list-windows -t ops
tmux display-message -t ops -p '#{session_name} #{window_name} #{window_index}'Sample output:
0: app- (1 panes) [80x24] [layout b25d,80x24,0,0,0] @0
1: logs* (1 panes) [80x24] [layout b260,80x24,0,0,1] @1 (active)
ops logs 1The * marks the active window. Switch inside tmux with Ctrl+b n, Ctrl+b p, or Ctrl+b 0–9.
Common Capture pane output for logs or scripts
Read what is visible in a pane without attaching interactively — handy for cron jobs or health checks.
Run the commands:
tmux new -d -s captest 'echo hello-from-tmux; sleep 30'
sleep 0.5
tmux capture-pane -t captest -p
tmux kill-session -t captestSample output:
hello-from-tmuxIf the pane is empty, the session may have exited before capture — use exec sleep or a longer-running command in the pane.
Common Send keystrokes to a pane remotely
send-keys injects keystrokes into the pane's current program state — it is not the same as running a shell command through a clean non-interactive shell.
Run the commands:
tmux new -d -s remote -n shell
tmux send-keys -t remote:shell 'top' Enter
tmux list-panes -t remote:shell
tmux kill-session -t remoteSample output:
0: [80x24] [history 0/2000, 960 bytes] %0 (active)Attach with tmux attach -t remote to see top running. Replace top with any command your workflow needs.
Common Print session metadata with -F format strings
Automation and monitoring scripts can query tmux without parsing tmux ls text.
Run the command:
tmux new -d -P -F 'session=#{session_name} windows=#{session_windows}' -s formatted 'sleep 30'
tmux kill-session -t formattedSample output:
session=formatted windows=1Use man tmux FORMATS section for placeholders like #{pane_id}, #{window_name}, and #{session_attached}.
Common Attach fails when the session name is wrong
A typical mistake after reboot or typo in the session name.
Run the command:
tmux attach -t nosuchSample output:
can't find session: nosuchRun tmux ls to see valid names. If the list is empty, the server has no sessions — start a new one with tmux new -s NAME.
Advanced Run a separate tmux server with -L
Isolate sessions (for example per project or per user script) with a named socket instead of the default default server.
Run the commands:
tmux -L dev new -d -s backend 'sleep 600'
tmux -L dev ls
tmux -L dev kill-serverSample output:
backend: 1 windows (created Wed Jul 1 14:16:50 2026)kill-server stops the named server. After killing the only session, the server normally exits automatically — kill-session -t backend alone is enough when no other sessions remain. Always pass the same -L dev flag to attach, list, or kill — otherwise you are talking to a different server.
Advanced Reload ~/.tmux.conf without restarting sessions
After editing bindings or colours, reload the config from inside tmux or from the shell.
Run the command (from the shell while sessions run):
tmux source-file ~/.tmux.confSample output:
No output usually means success. Errors are reported to the invoking tmux client. Check man tmux on your host for whether your version supports source-file -n (parse-only validation) or source-file -v (verbose parsed output). Startup config errors can also appear in the first session's pane when the server processes its initial configuration files.
Inside tmux you can also press Ctrl+b : then type source-file ~/.tmux.conf.
tmux — when to use / when not
| Use tmux when | Use something else when |
|---|---|
|
|
tmux vs screen
Both multiplex terminals and support detach/reattach. Behaviour differs in defaults, config, and maintenance.
| tmux | screen | |
|---|---|---|
| Status on modern distros | Commonly preferred and actively developed on modern Linux | Still used on legacy systems and environments standardized on GNU Screen |
| Layout model | Sessions → windows → panes | Sessions → windows (regions) |
| Scripting | Rich command set (split-window, formats, send-keys) |
Simpler command set |
| Config file | ~/.tmux.conf |
~/.screenrc |
| Prefix key | Ctrl+b (default) |
Ctrl+a (default) |
| Mouse support | Built-in option (set -g mouse on) |
Limited compared to tmux |
See the screen command if you maintain legacy hosts that still standardize on screen.
tmux — interview corner
What is tmux and why do admins use it?
tmux (terminal multiplexer) lets one terminal window host many shell sessions. A session survives when you detach or when SSH disconnects — processes inside keep running until you kill the session or reboot the host.
Typical workflow:
tmux new -s deploy
# run long job
# Ctrl+b d to detach
tmux attach -t deploy # laterThat matters on jump hosts and cloud VMs where you cannot leave a laptop connected all day.
A strong answer is:
"tmux multiplexes terminals — sessions, windows, and panes — and stays alive after detach or SSH drop. I use it for long deploys, log tailing, and keeping dev environments on remote servers."
What is the tmux prefix key?
The prefix is a lead key tmux waits for before treating the next keystroke as a command instead of sending it to the shell. Default prefix: Ctrl+b.
Example: Ctrl+b d means hold Ctrl, press b, release both, then press d — that detaches without killing processes.
Change it in ~/.tmux.conf:
set -g prefix C-a
unbind C-b
bind C-a send-prefixList current bindings:
tmux list-keys -T prefixA strong answer is:
"The prefix is the command leader — default Ctrl+b. I press prefix then d to detach, prefix then c for a new window, or prefix then quote/percent to split panes."
How do sessions, windows, and panes relate in tmux?
Think nested containers:
- Session — one connected workspace (often one project or one SSH login context)
- Window — full-screen tab inside a session (like browser tabs)
- Pane — split within the visible window (side-by-side or stacked shells)
One session can have many windows; one window can have many panes. Detaching leaves the session (and everything inside) running.
A strong answer is:
"Session is the top-level group that persists on detach. Windows are tabs; panes are splits inside the active window. I name sessions for projects and windows for roles like app versus logs."
What is the difference between tmux and screen?
Both solve terminal persistence and multiplexing. tmux has a clearer session/window/pane model, richer format strings, and stronger scripting support. screen is older; some legacy systems still standardize on it and use Ctrl+a as prefix.
| tmux | screen | |
|---|---|---|
| Prefix (default) | Ctrl+b | Ctrl+a |
| Config | ~/.tmux.conf | ~/.screenrc |
| Typical on RHEL 8+ / Ubuntu | Commonly preferred | Optional package; legacy standard |
A strong answer is:
"Both detach and reattach, but tmux is what I use on modern Linux — better pane layouts, richer format strings, and stronger scripting support. I fall back to screen only when it's the only multiplexer installed."
How do you list and attach to tmux sessions?
From the shell (outside tmux):
tmux ls
tmux attach -t session-nameSample tmux ls line:
work: 1 windows (created Wed Jul 1 14:18:30 2026)Inside tmux, Ctrl+b s opens an interactive session picker. Use tmux attach -d -t NAME to boot other clients off the same session.
A strong answer is:
"tmux ls lists sessions; tmux attach -t name reconnects. Inside tmux, prefix-s picks interactively. I name sessions after projects so ls output is obvious."
How do you split the screen in tmux?
Default key bindings (prefix Ctrl+b first):
| Layout | Binding |
|---|---|
| Top / bottom | Ctrl+b " |
| Left / right | Ctrl+b % |
From scripts:
tmux split-window -h # left/right
tmux split-window # top/bottomMove between panes with Ctrl+b o or arrow keys after prefix. Zoom one pane with Ctrl+b z.
A strong answer is:
"Prefix then double-quote splits horizontal stacks; prefix then percent splits vertical columns. I use Ctrl+b o to cycle panes and Ctrl+b z to zoom one pane for focus."
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
open terminal failed: not a terminal |
Running interactive tmux where stdout is not a TTY | Run from a real terminal or SSH session; use -d for detached sessions in scripts |
can't find session: NAME |
Session killed, renamed, or wrong socket | tmux ls; recreate with tmux new -s NAME or pass matching -L/-S |
no server running on /tmp/tmux-… |
No tmux server on that socket yet, or server exited after last session closed | tmux new -d starts one; check -L / -S matches how the session was created |
Keys like d or c go to the shell |
Prefix not pressed first | Press Ctrl+b, release, then the command key |
| Config changes ignored | Server already running with old options | tmux source-file ~/.tmux.conf or restart server after killing sessions |
duplicate session: NAME |
Session name already in use | Pick another -s name or attach to the existing session |

