Sessions: detach, reattach, never lose work
Sessions are the reason tmux exists. Learn these four commands and you already get most of tmux's value — everything else is convenience.
The core loop
Create a named session, work, detach, come back later. That's the loop you'll run for the rest of your career:
tmux new -s work # create + attach
# ... do things ...
# Ctrl-b d # detach: everything keeps running
tmux ls # see what's running
tmux attach -t work # pick up exactly where you left offThe SSH story (why people fall in love)
SSH into a server, start tmux, kick off a 6-hour job, close your laptop, drive home, SSH back in, tmux attach — the job never noticed. Any long-running remote work that isn't inside tmux (or similar) is one flaky connection away from dying.
One habit worth stealing
tmux new -As main attaches to "main" if it exists, creates it otherwise. Make it a shell alias and every terminal you ever open lands in the same persistent workspace:
alias t='tmux new -As main'Multiple sessions
One session per project keeps contexts clean. prefix s opens an interactive session tree — switch without detaching. prefix ( and ) cycle, prefix L toggles the last two, and prefix $ renames the current one.
Before moving on
- tmux new -s practice
- Detach with Ctrl-b d
- Run tmux ls and find it
- Reattach with tmux attach -t practice
- Bonus: create a second session and switch with Ctrl-b s