Every tmux Command Explained
tmux commands are issued either from the shell (tmux <command>), from inside tmux via
command mode (Prefix :), or directly as key bindings. This page covers the commands you will use day to day,
with their most useful flags and copy-ready examples, checked against tmux 3.7c. For the complete upstream option list, see the
searchable man tmux page.
The commands you will actually use
If you are new to tmux, these cover most day-to-day work. Everything else is documented below.
| What you want to do | Command |
|---|---|
| Start a session | tmux new -s work |
| List sessions | tmux ls |
| Reattach to a session | tmux attach -t work |
| Detach and leave it running | Prefix then d |
| Split the window | Prefix then % or " |
| Move between panes | Prefix then an arrow key |
| Kill a session | tmux kill-session -t work |
Session Commands
Sessions are the top level of the tmux hierarchy. A session groups multiple windows and continues running in the background even after you detach. Sessions survive SSH drops and can be reattached from any terminal.
# Create sessions
$ tmux new-session -s mysession # create and attach
$ tmux new-session -s mysession -d # create detached (background)
$ tmux new -s mysession -c ~/projects # set starting directory
# List sessions
$ tmux ls
$ tmux list-sessions
$ tmux ls -F '#{session_name}: #{session_windows} windows'
# Attach sessions
$ tmux attach -t mysession # attach by name
$ tmux attach # attach to most recent
$ tmux attach -t mysession -d # detach other clients first
# Detach, rename, kill
$ tmux detach-client # detach (also: Prefix d)
$ tmux rename-session -t old new # rename session
$ tmux kill-session -t mysession # kill one session
$ tmux kill-server # kill ALL sessions and server
$ tmux has-session -t mysession && echo "exists"
| Command | Alias / Short | Key Binding | Description |
|---|---|---|---|
new-session -s name | new -s name | — | Create a new named session |
list-sessions | ls | — | List all sessions |
attach-session -t name | attach -t name | — | Attach to a named session |
detach-client | — | Prefix d | Detach from current session |
rename-session -t old new | — | Prefix $ | Rename a session |
kill-session -t name | — | — | Kill a specific session |
kill-server | — | — | Kill tmux server and all sessions |
has-session -t name | — | — | Check if session exists (returns 0/1) |
switch-client -t name | switchc | — | Switch this client to another session |
choose-tree -s | — | Prefix s | Pick a session from an interactive tree |
switch-client -l | — | Prefix L | Switch to the last (previously used) session |
switch-client -p | — | Prefix ( | Switch to previous session |
switch-client -n | — | Prefix ) | Switch to next session |
Window Commands
Windows are tabs inside a session. Each window has its own set of panes and occupies the full terminal space. Use windows to organize different tasks within the same session.
$ tmux new-window -n logs # new window named 'logs'
$ tmux new-window -t dev:2 # new window at index 2 in 'dev'
$ tmux rename-window monitoring # rename current window
$ tmux select-window -t :2 # go to window index 2
$ tmux next-window # (Prefix n)
$ tmux previous-window # (Prefix p)
$ tmux last-window # toggle last window (Prefix l)
$ tmux kill-window -t :2 # kill window at index 2
$ tmux move-window -t dev:3 # move current window to session:index
$ tmux swap-window -s 2 -t 3 # swap window positions
$ tmux list-windows # list windows in current session
| Command | Key Binding | Description |
|---|---|---|
new-window -n name | Prefix c | Create new window (with optional name) |
rename-window name | Prefix , | Rename current window |
select-window -t :N | Prefix 0-9 | Select window by number |
next-window | Prefix n | Move to next window |
previous-window | Prefix p | Move to previous window |
last-window | Prefix l | Toggle between last two windows |
choose-tree -w | Prefix w | Interactive window chooser (all sessions) |
list-windows | — | Print windows in the current session |
find-window -N name | Prefix f | Search windows by name |
kill-window -t :N | Prefix & | Kill a window and all its panes |
move-window -t session:N | Prefix . | Move window to another session/index |
swap-window -s N -t M | — | Swap position of two windows |
move-window -r | — | Renumber windows to remove gaps in sequence |
Pane Commands
Panes are splits within a window. Each pane runs an independent shell. Panes can be resized, swapped, zoomed, and moved between windows.
# Splitting
$ tmux split-window -h # split horizontally (side by side)
$ tmux split-window -v # split vertically (top/bottom)
$ tmux split-window -h -l 30% # split, new pane gets 30% width
$ tmux split-window -h -c "#{pane_current_path}" # split, same directory
# Navigation
$ tmux select-pane -L # move focus left
$ tmux select-pane -R # move focus right
$ tmux select-pane -U # move focus up
$ tmux select-pane -D # move focus down
$ tmux select-pane -t :.+ # move to next pane (Prefix o)
# Resize Pane Commands
$ tmux resize-pane -L 10 # resize pane left by 10 cells
$ tmux resize-pane -R 10 # resize right by 10 cells
$ tmux resize-pane -U 5 # resize up by 5 lines
$ tmux resize-pane -D 5 # resize down by 5 lines
$ tmux resize-pane -Z # toggle zoom (fullscreen)
# Other operations
$ tmux kill-pane -t :. # kill current pane
$ tmux swap-pane -s :1 -t :2 # swap two panes
$ tmux break-pane # break pane into new window
$ tmux join-pane -s :2 -t :1 # merge window into pane
$ tmux display-panes # show pane numbers (Prefix q)
# Floating panes (tmux 3.7+, early feature) - full guide: tmux.app/doc/floating-panes/
$ tmux new-pane # floating pane over the layout (Prefix *)
$ tmux new-pane -x 80 -y 20 htop # 80x20 floating pane running htop
Default Key Bindings (Prefix: Ctrl+b)
All default key bindings after pressing the prefix key (Ctrl+b). List all with: tmux list-keys or Prefix ?.
| Binding | Action | Category |
|---|---|---|
| Prefix c | Create new window | Windows |
| Prefix n / p | Next / Previous window | Windows |
| Prefix l | Last (toggled) window | Windows |
| Prefix 0–9 | Select window by number | Windows |
| Prefix w | Interactive window chooser | Windows |
| Prefix , | Rename current window | Windows |
| Prefix & | Kill current window | Windows |
| Prefix % | Split pane horizontally | Panes |
| Prefix " | Split pane vertically | Panes |
| Prefix ↑↓←→ | Navigate between panes | Panes |
| Prefix o | Select next pane | Panes |
| Prefix z | Toggle pane zoom (fullscreen) | Panes |
| Prefix x | Kill current pane | Panes |
| Prefix q | Show pane numbers | Panes |
| Prefix { / } | Swap pane backward / forward | Panes |
| Prefix ! | Break pane into new window | Panes |
| Prefix Space | Cycle through pane layouts | Panes |
| Prefix Ctrl+↑↓←→ | Resize pane by 1 cell (repeatable) | Panes |
| Prefix Alt+↑↓←→ | Resize pane by 5 cells (repeatable) | Panes |
| Prefix Alt+1 … Alt+7 | Preset layouts: even-horizontal, even-vertical, main-horizontal, main-vertical, tiled, and mirrored main layouts (6–7, tmux 3.5+) | Panes |
| Prefix E | Spread panes out evenly | Panes |
| Prefix m / M | Mark pane / clear marked pane | Panes |
| Prefix * | New floating pane (tmux 3.7+) | Panes |
| Prefix d | Detach from session | Sessions |
| Prefix s | Interactive session chooser | Sessions |
| Prefix $ | Rename current session | Sessions |
| Prefix [ | Enter copy mode | Copy |
| Prefix ] | Paste from buffer | Copy |
| Prefix = | Choose paste buffer from list | Copy |
| Prefix : | Open command-line prompt | Misc |
| Prefix ? | List all key bindings | Misc |
| Prefix t | Show clock in current pane | Misc |
| Prefix D | Choose client to detach | Misc |
| Prefix L | Switch to last session | Sessions |
| Prefix / | Describe what a key does | Misc |
| Prefix C | Customize mode: browse and edit options and key bindings | Misc |
| Prefix i | Show window/pane info in the status line | Misc |
| Prefix ~ | Show message log | Misc |
| Prefix < / > | Window / pane context menus | Misc |
Copy Mode Commands
Copy mode lets you scroll through pane history, search, and copy text. Enter with Prefix [. Supports both emacs and vi key sets: the default is emacs unless $EDITOR or $VISUAL contains “vi”. The table below lists tmux's built-in defaults; the setup block remaps v and y so selection works like Vim.
# Enable vi keys in copy mode (.tmux.conf)
setw -g mode-keys vi
# Bind vi-style copy (add to .tmux.conf)
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind-key -T copy-mode-vi Escape send-keys -X cancel
# Enter copy mode from command line
$ tmux copy-mode
# Paste buffer
$ tmux paste-buffer
# List buffers
$ tmux list-buffers
# Save buffer to file
$ tmux save-buffer ~/clipboard.txt
| Key (vi mode) | Key (emacs mode) | Action |
|---|---|---|
| Prefix [ | Prefix [ | Enter copy mode |
| q | q / Esc | Exit copy mode |
| Esc | Ctrl-g | Clear selection |
| h j k l | ← ↓ ↑ → | Move cursor |
| 0 / $ / ^ | Ctrl-a / Ctrl-e / Alt-m | Line start / end / indentation |
| / | Ctrl-s | Search forward |
| ? | Ctrl-r | Search backward |
| n / N | n / N | Next / previous search match |
| Space | Ctrl-Space | Start selection |
| v | R | Toggle rectangle selection |
| V | — | Select whole line |
| Enter | Alt-w | Copy selection and exit |
| g / G | Alt-< / Alt-> | Jump to top / bottom of history |
| Ctrl-u / Ctrl-d | Alt-↑ / Alt-↓ | Scroll half page up / down |
| Ctrl-b / Ctrl-f | Alt-v / Ctrl-v | Scroll full page up / down |
| : | — | Go to line |
| Prefix ] | Prefix ] | Paste from buffer |
Server & Miscellaneous Commands
Commands to inspect and control the tmux server, display information, and manage options at runtime.
# Server information
$ tmux info # detailed server info
$ tmux -V # print tmux version
# Config
$ tmux source-file ~/.tmux.conf # reload config
$ tmux show-options -g # show all global options
$ tmux show-options -g | grep prefix # filter options
$ tmux set-option -g mouse on # set option at runtime
# Display
$ tmux display-message "Hello!" # show message in status bar
$ tmux display-message -p "#{session_name}" # print variable value
# List commands & keys
$ tmux list-commands # all available commands
$ tmux list-keys # all key bindings
$ tmux run-shell "echo test" # run shell command
Scripting Commands
Automate tmux sessions, send keystrokes to panes, and conditionally run commands from shell scripts.
# send-keys: run commands in a pane without focusing it
$ tmux send-keys -t dev:0 "npm run dev" Enter
$ tmux send-keys -t dev:0.1 "nvim ." Enter # target pane :window.pane
# send-prefix: send prefix key to a pane (for nested tmux)
$ tmux send-prefix -t dev:0
# has-session: check before attaching (useful in .bashrc)
$ tmux has-session -t dev 2>/dev/null && tmux attach -t dev || tmux new -s dev
# if-shell: conditional execution based on shell output
$ tmux if-shell "[ $(tmux -V | cut -c6) -gt 2 ]" "set -g mouse on"
# run-shell: run a command in the background
$ tmux run-shell "git pull origin main"
# Full session setup script example
$ tmux new-session -d -s dev -c ~/projects/myapp
$ tmux rename-window -t dev:0 'editor'
$ tmux send-keys -t dev:0 'nvim .' Enter
$ tmux split-window -h -t dev:0
$ tmux send-keys -t dev:0 'npm run dev' Enter
$ tmux new-window -t dev -n 'server'
$ tmux attach -t dev
Target Specification Syntax & CLI Scripting Primitives
When automating tmux via bash scripts, CI/CD pipelines, or external CLI tools, the -t target flag enables surgical control down to individual panes.
Target Spec Breakdown
Format: [session]:[window].[pane]
-t mysession— Target entire session-t mysession:1— Target window index 1-t mysession:1.0— Target pane index 0 in window 1-t :+/-t :-— Target next / previous window-t .{top-right}— Target pane by geographical corner
Programmatic Buffer Scraping
Extract live terminal text directly into shell scripts or LLM analysis tools using capture-pane:
# Dump last 500 lines of pane output to stdout
tmux capture-pane -p -S -500 -t dev:0.0
# Extract compile error lines
tmux capture-pane -p -t dev:0.1 | grep -i "error"
Literal String Injection
Send strings containing quotes, slashes, or special symbols without shell expansion:
# -l sends keys literally (no meta interpretation)
tmux send-keys -l -t dev:0 'echo "$PWD && ls -la"'
tmux send-keys -t dev:0 Enter
Need a quick scannable reference?
The /cheat-sheet/ is a printable visual grid of every key binding — perfect to print and keep by your terminal.