Quick Reference

Cheatsheets

Practical command references for Linux, networking, servers, containers, databases, and more.

Cheatsheet#tmux-cheatsheet

Tmux Cheatsheet

Tmux (Terminal Multiplexer) allows you to run multiple terminal sessions inside a single window. It also keeps processes running in the background even if you disconnect from SSH.

Installation

# Debian/Ubuntu
sudo apt install tmux
 
# RHEL / CentOS / Fedora
sudo dnf install tmux
 
# Arch Linux
sudo pacman -S tmux
 
# macOS
brew install tmux

Session Management

Run these commands in your regular terminal.

tmux                     # Start a new session
tmux new -s mysession    # Start a new session with name "mysession"
tmux ls                  # List active sessions
tmux a                   # Attach to the last active session
tmux a -t mysession      # Attach to "mysession"
tmux kill-session -t mysession  # Kill "mysession"
tmux kill-server         # Kill all tmux sessions

Prefix Key

Inside Tmux, all shortcuts start with a prefix key. By default, the prefix is Ctrl + b.

Window Management (Tabs)

After pressing Ctrl + b:

  • c : Create a new window
  • w : List all windows and choose one
  • n : Go to next window
  • p : Go to previous window
  • 0 to 9 : Go to a specific window number
  • , : Rename current window
  • & : Kill current window

Pane Management (Splits)

After pressing Ctrl + b:

  • % : Split pane vertically (left/right)
  • " : Split pane horizontally (top/bottom)
  • Arrow Keys : Switch between panes
  • x : Kill current pane
  • z : Toggle pane zoom (fullscreen)
  • Space : Cycle through pane layouts
  • { / } : Swap pane with the next/previous pane

Copy Mode (Scrollback)

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

After pressing Ctrl + b:

  • [ : Enter copy mode (use arrow keys or PgUp/PgDn to scroll)
  • q : Exit copy mode
  • Space : Start selection (in copy mode)
  • Enter : Copy selection and exit copy mode
  • ] : Paste the copied text

With set -g mode-keys vi in your config, you can use Vim-style keys (hjkl, /search) in copy mode.

Scripting and Automation

# Send a command to a running tmux session from outside
tmux send-keys -t mysession "echo hello" Enter
 
# Create a new session with pre-configured windows
tmux new-session -d -s dev -n editor
tmux send-keys -t dev:editor "nvim" Enter
tmux new-window -t dev -n server
tmux send-keys -t dev:server "npm run dev" Enter
tmux attach -t dev

Configuration (~/.tmux.conf)

You can customize the prefix and appearance in ~/.tmux.conf. After changing it, reload with tmux source-file ~/.tmux.conf.

# Change prefix to Ctrl + a (like GNU Screen)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
 
# Enable mouse support (scroll, click, resize panes)
set -g mouse on
 
# Use Vim-style keys in copy mode
set -g mode-keys vi
 
# Start window numbering from 1 instead of 0
set -g base-index 1
setw -g pane-base-index 1