Skip to content

tmux

105 commands

A terminal multiplexer: split windows into panes, keep sessions alive after disconnect and script complex layouts.

  • terminal
  • sessions
  • productivity

Install tmux

sudo apt install tmux

Session Start2

tmux

Starts a new tmux session with a default numerical name.

tmux new -s [name]

Starts a new session with a specific custom name for easier identification.

Link

Session Management8

tmux ls

Lists all currently running tmux sessions.

tmux attach -t [name]

Attaches to an existing background session identified by its name.

Link
tmux attach -d -t [name]

Attaches to a session and detaches any other clients currently attached to it.

Link
Prefix + d

Detaches from the current session, leaving it running in the background.

Link
tmux rename-session -t [current] [new]

Renames an existing session to a new label.

Link
Prefix + $

Interactively prompts to rename the current session.

Link
tmux kill-session -t [name]

Terminates a specific session and closes all its windows and panes.

Link
tmux kill-server

Kills the tmux server and all sessions, windows, and panes immediately.

Link

Window Management9

Prefix + c

Creates a new window within the current session.

Link
tmux new-window -n [name]

Creates a new window with a specified name.

Link
Prefix + ,

Prompts to rename the current window.

Link
Prefix + n

Switches to the next window in the list.

Link
Prefix + p

Switches to the previous window in the list.

Link
Prefix + [number]

Switches directly to the window at the specified index.

Link
Prefix + w

Opens an interactive list to select a specific window from any session.

Link
Prefix + &

Prompts confirmation to kill (close) the current window.

Link
tmux move-window -r

Renumbers all windows in the session sequentially to remove gaps.

Link

Pane Management14

Prefix + %

Splits the current pane vertically into two side-by-side panes.

Link
Prefix + "

Splits the current pane horizontally into two top-and-bottom panes.

Link
Prefix + o

Cycles focus to the next pane in the current window.

Link
Prefix + Arrow Key

Moves focus to the pane in the direction of the arrow key.

Link
Prefix + x

Prompts confirmation to kill (close) the current pane.

Link
Prefix + z

Toggles zoom on the current pane, making it fill the entire window.

Link
Prefix + {

Swaps the current pane with the previous pane.

Link
Prefix + }

Swaps the current pane with the next pane.

Link
Prefix + Space

Cycles through the available automated pane layouts.

Link
tmux break-pane

Detaches the current pane and moves it into its own new window.

Link
tmux join-pane -t [window]

Moves the current pane into an existing window.

Link
tmux resize-pane -[U/D/L/R] [amount]

Resizes the current pane in a specific direction by a number of cells.

Link
tmux display-panes

Briefly displays the index numbers of visible panes.

Link
tmux select-pane -t [id]

Selects a pane directly by its visible index number.

Link

Copy Mode & Scrollback9

Prefix + [

Enters copy mode to scroll through history and select text.

Link
Prefix + PgUp

Enters copy mode and scrolls up one page immediately.

Link
q

Quits copy mode and returns to the command prompt.

Link
g

Goes to the very top of the scrollback history.

Link
G

Goes to the very bottom of the scrollback history.

Link
/

Searches forward in the scrollback buffer for a specific pattern.

Link
?

Searches backward in the scrollback buffer for a specific pattern.

Link
Space

Starts text selection in copy mode.

Link
Enter

Copies the selected text to the tmux paste buffer and exits copy mode.

Link

Buffer Management5

Prefix + ]

Pastes the most recently copied text from the tmux buffer.

Link
tmux list-buffers

Displays a history of copied text segments stored in buffers.

Link
tmux show-buffer

Displays the contents of the current paste buffer without pasting it.

Link
tmux save-buffer [file]

Saves the contents of the paste buffer to a file.

Link
tmux load-buffer [file]

Loads text from a file into a new paste buffer.

Link

Configuration9

tmux show-options -g

Displays the global session options currently active.

Link
tmux show-window-options -g

Displays the global window options currently active.

Link
tmux source-file [path]

Reloads the tmux configuration file without restarting the server.

Link
Prefix + :

Opens the tmux command prompt for entering commands interactively.

Link
tmux set-option -g history-limit [lines]

Increases the scrollback buffer size to store more history.

Link
tmux set-option -g base-index 1

Sets window numbering to start at 1 instead of 0.

Link
tmux set-window-option -g pane-base-index 1

Sets pane numbering to start at 1 instead of 0.

Link
tmux set-option -g renumber-windows on

Automatically renumbers windows when one is closed.

Link
tmux set-option -g mouse on

Enables mouse support for selecting panes and resizing.

Link

Key Bindings3

tmux list-keys

Lists all current key bindings.

Link
tmux bind-key [key] [command]

Binds a specific command to a key combination.

Link
tmux unbind-key [key]

Removes a specific key binding.

Link

Environment2

tmux show-environment

Displays the global environment variables for the tmux session.

Link
tmux set-environment [name] [value]

Sets a global environment variable for the session.

Link

Status Bar Customization4

tmux set-option -g status-position [top/bottom]

Moves the status bar to the top or bottom of the screen.

Link
tmux set-option -g status-bg [color]

Changes the background color of the status bar.

Link
tmux set-option -g status-left-length [number]

Increases the character limit for the left side of the status bar.

Link
tmux set-option -g status-interval [seconds]

Sets how frequently the status bar updates in seconds.

Link

Automation & Scripting6

tmux new-session -d -s [name] '[command]'

Starts a detached session that immediately runs a specific background command.

Link
tmux send-keys -t [target] '[keys]' Enter

Sends keystrokes to a specific pane as if typed by the user.

Link
tmux run-shell '[script]'

Executes a shell command or script in the background.

Link
tmux if-shell '[condition]' '[cmd1]' '[cmd2]'

Executes a tmux command conditionally based on a shell command's success.

Link
tmux wait-for [channel]

Blocks execution until a signal is received on a specific channel.

Link
tmux wait-for -S [channel]

Sends a signal to a waiting tmux client to resume execution.

Link

Operational Workflows6

tmux set-window-option synchronize-panes on

Broadcasts all keystrokes to every pane in the current window simultaneously.

Link
tmux pipe-pane -o '[command]'

Pipes all output from the current pane to a file for logging.

Link
tmux pipe-pane

Stops piping output from the current pane.

Link
tmux capture-pane -S -

Captures the entire visible text and scrollback history of the pane into a buffer.

Link
tmux respawn-pane -k

Kills the process in the pane and restarts the shell or original command.

Link
tmux respawn-window -k

Kills processes in the window and restarts the window environment.

Link

Blue Team Defensive6

tmux set-window-option monitor-activity on

Highlights the window in the status bar if output activity is detected.

Link
tmux set-window-option monitor-silence [seconds]

Alerts if no output is received in a pane for a specified duration.

Link
tmux set-option -g visual-bell on

Flashes the status bar instead of making a sound when a bell occurs.

Link
tmux lock-session

Locks the session requiring a password (if configured) to resume.

Link
tmux list-clients

Shows all users or terminals currently attached to the session.

Link
tmux detach-client -t [client]

Forcibly removes a specific client connection from the session.

Link

Incident Response2

tmux new -s IR -d; tmux pipe-pane -t IR -o 'cat >> ir_log.txt'

Workflow to start a detached session and immediately begin logging everything.

Link
tmux clock-mode

Displays a large digital clock, useful for timestamping screenshots.

Link

Advanced Workflow9

tmux link-window -s [src] -t [dst]

Links a window so it appears in multiple sessions simultaneously.

Link
tmux unlink-window -t [target]

Removes a linked window from the current session without destroying it.

Link
tmux refresh-client -S

Updates the client status line and redraws the screen.

Link
tmux select-layout tiled

Arranges all panes in the current window in a tiled grid.

Link
tmux select-layout even-horizontal

Arranges all panes in equal-width columns.

Link
tmux select-layout even-vertical

Arranges all panes in equal-height rows.

Link
tmux select-layout main-horizontal

Arranges one large main pane on top and smaller panes below.

Link
tmux select-layout main-vertical

Arranges one large main pane on the left and smaller panes on the right.

Link
tmux rotate-window

Rotates the positions of panes within the current window.

Link

Shared Sessions3

tmux -S /tmp/shared_socket new -s shared

Creates a session using a specific socket file for multi-user access.

Link
tmux -S /tmp/shared_socket attach -t shared

Attaches to a session located at a specific socket path.

Link
chmod 777 /tmp/shared_socket

External command often used to grant permissions for shared socket access.

Link

SOC Workflow3

tmux split-window -h 'htop'; tmux split-window -v 'tail -f /var/log/syslog'

One-line command to set up a monitoring dashboard.

Link
tmux set-hook -g alert-activity 'run-shell "echo Alert >> ~/alerts.log"'

Configures a hook to run a script whenever activity is detected.

Link
tmux set-hook -g session-created 'source-file ~/.tmux_soc.conf'

Automatically applies a specific config when a new session is created.

Link

Scripting2

tmux list-panes -a -F '#{pane_id} #{pane_current_command}'

Lists all panes and their currently running commands using a format string.

Link
tmux list-windows -F '#{window_index}: #{window_name}'

Lists windows with a custom output format for scripting parsing.

Link

Advanced3

tmux switch-client -t [session]

Switches the current client to a different session without detaching.

Link
tmux last-window

Toggles between the current window and the previously selected window.

Link
tmux last-pane

Toggles between the current pane and the previously active pane.

Link