Skip to content

Drill: tmux Session Management

Goal

Use tmux to manage persistent terminal sessions with windows, panes, and detach/attach workflows.

Setup

  • Install tmux (apt install tmux or yum install tmux)
  • A terminal emulator

Commands

Start a new named session:

tmux new-session -s work

Detach from a session (inside tmux):

Ctrl+b, d

List existing sessions:

tmux list-sessions

Attach to an existing session:

tmux attach -t work

Create a new window (inside tmux):

Ctrl+b, c

Switch between windows:

Ctrl+b, n    # next window
Ctrl+b, p    # previous window
Ctrl+b, 0-9  # window by number

Split pane horizontally:

Ctrl+b, "

Split pane vertically:

Ctrl+b, %

Navigate between panes:

Ctrl+b, arrow keys

Resize panes:

Ctrl+b, Ctrl+arrow keys

Enter copy/scroll mode:

Ctrl+b, [        # enter copy mode
q                # exit copy mode

Kill a pane or window:

Ctrl+b, x        # kill current pane (confirms)

Rename the current window:

Ctrl+b, ,

Create a session from the command line with a layout:

tmux new-session -d -s devops -n editor
tmux send-keys -t devops:editor 'vim' C-m
tmux new-window -t devops -n logs
tmux send-keys -t devops:logs 'journalctl -f' C-m
tmux new-window -t devops -n shell
tmux attach -t devops

Kill a session:

tmux kill-session -t work

What to Look For

  • Sessions persist after detaching; reconnect from any terminal
  • Windows are like tabs; panes are splits within a window
  • Copy mode lets you scroll back through terminal output
  • Scripted session creation automates your workspace layout

Common Mistakes

  • Forgetting the prefix key (Ctrl+b) before tmux commands
  • Nesting tmux sessions (attach inside tmux) causing double-prefix confusion
  • Not naming sessions and losing track of which is which
  • Not knowing about copy mode and losing scrollback history

Cleanup

tmux kill-server  # kills all sessions

Or kill individual sessions:

tmux kill-session -t work
tmux kill-session -t devops