/user/kayd @ devops :~$ cat tmux.md

tmux Cheatsheet tmux Cheatsheet

QR Code linking to: tmux Cheatsheet
Karandeep Singh
Karandeep Singh
• 6 minutes

Summary

My tmux notes. Session management, window and pane keybindings, copy mode, config essentials, and scripting layouts with send-keys.

Half my job happens inside tmux: long-running deploys that survive dropped SSH connections, split panes tailing logs on three servers at once, a scripted dev layout that comes up with one command. These are the commands and keybindings I actually use, nothing more. Pair it with my Bash CLI One-Liners Cheatsheet for what to run inside those panes.

All keybindings below assume the default prefix Ctrl-b (written C-b). Press the prefix, release, then press the key.

Sessions

Docs: Getting Started on the tmux wiki

tmux new -s deploy            # new named session
tmux new -s deploy -d         # new session, detached (great in scripts)
tmux ls                       # list sessions
tmux attach -t deploy         # attach to a session by name
tmux attach -d -t deploy      # attach and detach any other client
tmux kill-session -t deploy   # kill one session
tmux kill-server              # kill everything
tmux rename-session -t 0 work # rename a session
KeybindingAction
C-b dDetach from session (it keeps running)
C-b sInteractive session picker
C-b $Rename current session
C-b ( / C-b )Previous / next session

The whole point: detach with C-b d, close your laptop, SSH back in later, tmux attach -t deploy, and your job is still running.

Windows

Docs: tmux(1) on man.openbsd.org

Windows are like tabs inside a session.

KeybindingAction
C-b cCreate new window
C-b ,Rename current window
C-b nNext window
C-b pPrevious window
C-b 0-9Jump to window by number
C-b wInteractive window picker
C-b &Kill current window (confirms)
C-b .Move window to a new index
C-b fFind window by name

Panes

Docs: tmux(1) on man.openbsd.org

Panes split a window into multiple terminals.

KeybindingAction
C-b %Split vertically (side by side)
C-b "Split horizontally (stacked)
C-b oCycle to next pane
C-b ;Toggle to last-active pane
C-b arrowsMove to pane in that direction
C-b zZoom pane fullscreen (toggle)
C-b xKill current pane (confirms)
C-b { / C-b }Swap pane left / right
C-b !Break pane out into its own window
C-b qShow pane numbers (press number to jump)
C-b SpaceCycle through preset layouts

C-b z is the one to memorize. Zoom a pane to read logs full-screen, hit it again to drop back to the split.

Resizing & Layouts

Docs: tmux(1) on man.openbsd.org

KeybindingAction
C-b C-arrowsResize pane by 1 cell (hold prefix, tap arrow)
C-b M-arrowsResize pane by 5 cells
C-b M-1M-5Apply preset layout (even-horizontal, even-vertical, main-horizontal, main-vertical, tiled)
tmux resize-pane -D 10        # resize down 10 cells (also -U, -L, -R)
tmux select-layout tiled      # apply a layout from the command line

Copy Mode & Scrollback

Docs: Getting Started on the tmux wiki

KeybindingAction
C-b [Enter copy mode (scrollback)
qExit copy mode
C-b ]Paste most recent buffer
C-b PgUpEnter copy mode scrolled up one page

With vi keys enabled (see config below), inside copy mode:

KeyAction
k / j, C-u / C-dScroll up / down, half-page up / down
g / GTop / bottom of scrollback
/ then textSearch down (? searches up)
n / NNext / previous search match
SpaceStart selection
Enter (or y)Copy selection and exit
tmux show-buffer              # print last copied buffer
tmux list-buffers             # all paste buffers
tmux save-buffer /tmp/out.txt # dump buffer to a file

Synchronize Panes

Docs: tmux(1) on man.openbsd.org

Type into every pane in the window at once. Handy when you have a handful of servers open in splits and want to run the same command on all of them.

# toggle on/off (prompt shows "synchronize-panes on")
C-b : setw synchronize-panes

~/.tmux.conf Essentials

Docs: tmux wiki

# Remap prefix from C-b to C-a (easier to reach)
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Mouse support: click panes, drag borders, wheel scroll
set -g mouse on

# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1

# vi keys in copy mode
setw -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

# Bigger scrollback, faster escape, sane colors
set -g history-limit 50000
set -sg escape-time 10
set -g default-terminal "tmux-256color"

# Renumber windows when one closes
set -g renumber-windows on

# Intuitive split keys that keep the current path
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# Status line: session name, window list, host + time
set -g status-style bg=black,fg=green
set -g status-left "[#S] "
set -g status-right "#h %H:%M"

Reload without restarting:

tmux source-file ~/.tmux.conf     # or: C-b : source-file ~/.tmux.conf

Scripting tmux

Docs: tmux(1) on man.openbsd.org

send-keys and split-window let you build a whole dev environment in one script:

#!/usr/bin/env bash
SESSION="dev"

tmux new-session -d -s "$SESSION" -n editor
tmux send-keys -t "$SESSION:editor" 'cd ~/project && vim .' C-m

tmux split-window -h -t "$SESSION:editor"
tmux send-keys -t "$SESSION:editor.1" 'cd ~/project && hugo server -D' C-m

tmux new-window -t "$SESSION" -n logs
tmux send-keys -t "$SESSION:logs" 'journalctl -f' C-m

tmux select-window -t "$SESSION:editor"
tmux attach -t "$SESSION"

Notes: C-m is Enter; targets are session:window.pane; new-session -d means the script works even when run outside tmux. Idempotent version: tmux has-session -t dev 2>/dev/null || ./dev-env.sh.

Nested tmux (SSH Into a Server Running tmux)

Docs: tmux(1) on man.openbsd.org

When you run tmux locally and attach to a remote tmux over SSH, press the prefix twice to send it to the inner session: C-b C-b c creates a window on the remote. If you nest often, set the remote prefix to something else (e.g. C-a) so the two never collide.

Most-Used Commands

Docs: tmux(1) on man.openbsd.org

CommandWhat it does
tmux new -s nameNew named session
tmux lsList sessions
tmux attach -t nameAttach to session
tmux kill-session -t nameKill session
C-b dDetach
C-b c / C-b n / C-b pNew / next / previous window
C-b % / C-b "Vertical / horizontal split
C-b zZoom pane
C-b [Copy mode / scrollback
C-b : setw synchronize-panesType into all panes

Most of this pays off on remote boxes. See my Ubuntu Terminal Cheatsheet for the server-side commands you’ll be running inside those sessions.

  • Bash CLI One-Liners: the find/grep/jq/rsync pipelines I end up typing inside these panes
  • Ubuntu Terminal: apt, systemd, and journalctl on the servers these sessions are attached to
  • Amazon Linux 2 Terminal: the same idea for EC2, with yum, extras repos, SSM sessions, and instance-metadata queries

The rest of my terminal notes live in the Terminal group, and everything else is in the cheatsheet library.

Similar Articles

More from devops

Jenkins Cheatsheet

Jenkins cheatsheet with declarative pipeline syntax, credentials, parameters, parallel stages, …

Docker Cheatsheet

Docker cheatsheet with the commands I use daily as a DevOps engineer: image builds, run flags, …

Bash Basics Cheatsheet

Quick-reference Bash basics cheatsheet: variables, parameter expansion, conditionals, loops, arrays, …

Ansible Cheatsheet

Ansible cheatsheet with inventory formats, ad-hoc commands, playbook anatomy, common modules, …