Drill: tmux Session Management¶
Goal¶
Use tmux to manage persistent terminal sessions with windows, panes, and detach/attach workflows.
Setup¶
- Install tmux (
apt install tmuxoryum install tmux) - A terminal emulator
Commands¶
Start a new named session:
Detach from a session (inside tmux):
List existing sessions:
Attach to an existing session:
Create a new window (inside tmux):
Switch between windows:
Split pane horizontally:
Split pane vertically:
Navigate between panes:
Resize panes:
Enter copy/scroll mode:
Kill a pane or window:
Rename the current window:
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:
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¶
Or kill individual sessions: