Skip to Content
32 CheatsheetsK8sTmux / Tmux Cheatsheet

Tmux Cheatsheet

Table of Contents

  1. Getting Started
  2. Sessions
  3. Windows
  4. Panes
  5. Resizing Panes
  6. Copy Mode
  7. Layouts
  8. Key Bindings
  9. Configuration
  10. Plugins (TPM)
  11. Scripting & Automation
  12. Interview Scenarios

Getting Started

Installation

# Debian / Ubuntu sudo apt install tmux # macOS (Homebrew) brew install tmux # RHEL / CentOS / Fedora sudo dnf install tmux # Check version tmux -V

The Prefix Key

All tmux key bindings are preceded by a prefix key (default: Ctrl+b).

ActionKey
Send prefix to applicationCtrl+b Ctrl+b
Change prefix to Ctrl+aAdd set -g prefix C-a to ~/.tmux.conf

Sessions

Starting & Stopping Sessions

tmux # Start a new unnamed session tmux new-session # Same as above tmux new -s mysession # Start a named session tmux new -s mysession -d # Start a session in the background (detached) tmux kill-session -t mysession # Kill a named session tmux kill-server # Kill all sessions and the tmux server

Attaching & Detaching

tmux attach # Attach to the most recent session tmux attach -t mysession # Attach to a named session tmux a -t mysession # Short form
KeyAction
Ctrl+b dDetach from the current session
Ctrl+b DChoose a client to detach

Listing & Switching Sessions

tmux ls # List all sessions tmux list-sessions # Long form
KeyAction
Ctrl+b sInteractive session selector
Ctrl+b $Rename the current session
Ctrl+b (Switch to the previous session
Ctrl+b )Switch to the next session
Ctrl+b LSwitch to the last (most recently used) session

Windows

Windows are like tabs within a session.

Creating & Closing Windows

KeyAction
Ctrl+b cCreate a new window
Ctrl+b &Close the current window (with confirmation)
tmux new-window -n mywindow # Create a named window from command line
KeyAction
Ctrl+b nNext window
Ctrl+b pPrevious window
Ctrl+b 0–9Switch to window by number
Ctrl+b 'Prompt for window index to switch to
Ctrl+b wInteractive window selector
Ctrl+b lSwitch to the last (previously selected) window
Ctrl+b fFind window by name

Managing Windows

KeyAction
Ctrl+b ,Rename the current window
Ctrl+b .Move window (prompts for new index)

Panes

Panes split a window into multiple terminal areas.

Splitting Panes

KeyAction
Ctrl+b %Split pane left/right
Ctrl+b "Split pane top/bottom
tmux split-window -h # Split pane left/right tmux split-window -v # Split pane top/bottom
KeyAction
Ctrl+b ArrowMove to pane in arrow direction
Ctrl+b oCycle through panes
Ctrl+b ;Switch to the last active pane
Ctrl+b qShow pane numbers (press number to jump)

Managing Panes

KeyAction
Ctrl+b xClose the current pane (with confirmation)
Ctrl+b zToggle pane zoom (full-screen)
Ctrl+b !Break pane into its own window
Ctrl+b {Swap pane with the previous pane
Ctrl+b }Swap pane with the next pane
Ctrl+b SpaceCycle through built-in layouts

Resizing Panes

Hold Ctrl+b, then press and hold the arrow key, or use these shortcuts:

KeyAction
Ctrl+b Ctrl+ArrowResize pane by 1 cell
Ctrl+b Alt+ArrowResize pane by 5 cells
tmux resize-pane -D 5 # Resize down by 5 tmux resize-pane -U 5 # Resize up by 5 tmux resize-pane -L 5 # Resize left by 5 tmux resize-pane -R 5 # Resize right by 5 tmux resize-pane -t 1 -x 80 # Set pane 1 to 80 columns wide

Copy Mode

Copy mode lets you scroll through terminal history and copy text.

Entering & Exiting

KeyAction
Ctrl+b [Enter copy mode
q or EscExit copy mode
Ctrl+b ]Paste copied text
KeyAction
h j k lMove cursor (vi directions)
Ctrl+u / Ctrl+dScroll up / down half page
Ctrl+b / Ctrl+fScroll up / down full page
g / GGo to top / bottom
/Search forward
?Search backward
n / NNext / previous search match
SpaceStart selection
EnterCopy selection and exit copy mode

Enable vi Keys in ~/.tmux.conf

set-window-option -g mode-keys vi 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

Layouts

tmux provides five built-in pane layouts cycled with Ctrl+b Space:

LayoutDescription
even-horizontalAll panes same width, side by side
even-verticalAll panes same height, stacked
main-horizontalOne large pane on top, smaller panes below
main-verticalOne large pane on left, smaller panes on right
tiledPanes arranged in a grid
tmux select-layout tiled # Apply tiled layout from command line tmux select-layout main-vertical

Key Bindings

Miscellaneous

KeyAction
Ctrl+b ?Show all key bindings
Ctrl+b :Open the tmux command prompt
Ctrl+b tShow a clock in the current pane
Ctrl+b ~Show previous tmux messages
Ctrl+b iDisplay pane information
Ctrl+b rReload config (if bound in ~/.tmux.conf)

Custom Bindings Example (~/.tmux.conf)

# Reload config bind r source-file ~/.tmux.conf \; display "Config reloaded!" # Easier splits bind | split-window -h bind - split-window -v # Vim-style pane navigation bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R

Configuration

Sample ~/.tmux.conf

# Use Ctrl+a as prefix (like GNU Screen) unbind C-b set -g prefix C-a bind C-a send-prefix # Enable 256 colors set -g default-terminal "screen-256color" # Enable mouse support set -g mouse on # Increase history limit set -g history-limit 50000 # Start window and pane index at 1 set -g base-index 1 setw -g pane-base-index 1 # Renumber windows automatically set -g renumber-windows on # Status bar set -g status-bg colour235 set -g status-fg colour136 set -g status-interval 5 set -g status-right "#H | %Y-%m-%d %H:%M" # Highlight active window setw -g window-status-current-style fg=colour166,bold # Vi mode for copy setw -g mode-keys vi # Reload config binding bind r source-file ~/.tmux.conf \; display "Config reloaded!" # Easier splits bind | split-window -h -c "#{pane_current_path}" bind - split-window -v -c "#{pane_current_path}" unbind '"' unbind %

Plugins (TPM)

Tmux Plugin Manager (TPM)  makes it easy to install and manage plugins.

Install TPM

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Add to ~/.tmux.conf

# List plugins set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-sensible' set -g @plugin 'tmux-plugins/tmux-resurrect' # Save/restore sessions set -g @plugin 'tmux-plugins/tmux-continuum' # Automatic saving set -g @plugin 'tmux-plugins/tmux-yank' # Copy to system clipboard # Initialize TPM (keep this at the bottom) run '~/.tmux/plugins/tpm/tpm'

TPM Key Bindings

KeyAction
Ctrl+b IInstall plugins
Ctrl+b UUpdate plugins
Ctrl+b Alt+uRemove/uninstall plugins not in list
PluginPurpose
tmux-sensibleSensible defaults everyone can agree on
tmux-resurrectSave and restore tmux sessions across reboots
tmux-continuumAutomatic session saving and restore on start
tmux-yankCopy to system clipboard in copy mode
tmux-fzfFuzzy find sessions, windows, and panes
tmux-themepackCollection of status bar themes

Scripting & Automation

Run a Command in a New Session

tmux new-session -d -s work -x 220 -y 50 tmux send-keys -t work 'vim .' Enter tmux attach -t work

Multi-pane Setup Script

#!/usr/bin/env bash SESSION="dev" tmux new-session -d -s $SESSION # Window 1: editor tmux rename-window -t $SESSION:1 'editor' tmux send-keys -t $SESSION:1 'vim .' Enter # Window 2: split — server + logs tmux new-window -t $SESSION -n 'server' tmux split-window -h -t $SESSION:server tmux send-keys -t $SESSION:server.left 'npm run dev' Enter tmux send-keys -t $SESSION:server.right 'tail -f server.log' Enter # Window 3: shell tmux new-window -t $SESSION -n 'shell' tmux select-window -t $SESSION:editor tmux attach -t $SESSION

Useful tmux Commands

tmux list-keys # List all key bindings tmux list-commands # List all tmux commands tmux show-options -g # Show all global options tmux show-window-options -g # Show all global window options tmux display-message "hello tmux" # Display a message in status bar tmux pipe-pane -o 'cat >> ~/pane.log' # Log pane output to file tmux set -g mouse on # Enable mouse at runtime

Interview Scenarios

Scenario 1: Keep a Long-Running Job Alive After SSH Disconnect

# Start a named session and run the job inside it tmux new -s etl python run_pipeline.py # Detach and disconnect safely Ctrl+b d # Reconnect later tmux attach -t etl

Scenario 2: Pair Programming / Shared Terminal

# Host: start a session tmux new -s shared # Guest: attach to the same session (read-write) tmux attach -t shared # Guest: attach in read-only mode tmux attach -t shared -r

Scenario 3: Monitor Multiple Servers at Once

#!/usr/bin/env bash SERVERS=(web1 web2 db1) SESSION="monitor" tmux new-session -d -s $SESSION for i in "${!SERVERS[@]}"; do if [ $i -eq 0 ]; then tmux send-keys -t $SESSION "ssh ${SERVERS[$i]}" Enter else tmux split-window -t $SESSION -v tmux send-keys -t $SESSION "ssh ${SERVERS[$i]}" Enter fi done tmux select-layout -t $SESSION tiled tmux attach -t $SESSION

Scenario 4: Persist Sessions Across Reboots

# Install tmux-resurrect via TPM set -g @plugin 'tmux-plugins/tmux-resurrect' # Save session manually Ctrl+b Ctrl+s # Restore session after reboot Ctrl+b Ctrl+r

Common Interview Questions

QuestionAnswer
How do you run a process that survives SSH logout?Use tmux new -s name, run the process, then detach with Ctrl+b d
Difference between a session, window, and pane?Session = server-side context; Window = tab in session; Pane = split within a window
How do you share a terminal with a colleague?Both attach to the same session: tmux attach -t session
How do you save and restore sessions?Use the tmux-resurrect plugin (Ctrl+b Ctrl+s / Ctrl+b Ctrl+r)
How do you scroll up in tmux?Enter copy mode with Ctrl+b [, then use arrow keys or Ctrl+u/Ctrl+d
Last updated on