- Published at
tmux cheatsheet
Quick tmux commands to start, scroll, detach/attach, and restore sessions.
Table of Contents
tmux cheatsheet
Start a new session
# New session named "dev"
tmux new -s dev
# New session and run a command inside it
# (session ends when the command exits)
tmux new -s oneoff "npm run dev"
List, attach, detach
# List sessions
tmux ls
# Attach to a session by name
tmux attach -t dev
# Attach to the most recent session
tmux attach
Detach from the current session:
- Press Prefix then d (default Prefix is Ctrl-b), i.e. Ctrl-b d
Scroll in a tmux session (copy mode)
- Enter copy mode: Prefix then [ (Ctrl-b [)
- Move: Arrow keys, PageUp/PageDown; vi-style keys also work (h/j/k/l)
- Search forward/backward: / and ?
- Exit copy mode: q
Select and copy text (optional):
- Start selection: Space
- End selection (copy to tmux buffer): Enter
- Paste: Prefix then ] (Ctrl-b ])
Enable mouse scrolling (temporary):
tmux set -g mouse on
Persist mouse in your ~/.tmux.conf
:
set -g mouse on
Restore a session (reattach)
If you detached or got disconnected:
# Reattach by name
tmux attach -t dev
# Or attach to the last session
tmux attach
Notes:
- Sessions live as long as the tmux server runs. If the server stops (e.g., reboot), sessions end.
- For automatic save/restore across reboots, consider plugins like tmux-resurrect (optional).