learntmux.dev

Detach and come back

Goal

tail is still running in window 0 after you detach from learn and reattach.

C-b d detaches: your terminal leaves the session, but the session and everything running in it stay alive on the server. tmux attach -t learn puts you back exactly where you were.

The difference that matters, and the one that costs people work:

exit, or closing the terminal
ends the shell in the pane, and with it the window and the session
C-b d
ends only the client, the link between your terminal and the server

Programs inside a detached session never notice they were left.

Do this

Run tail -f ~/build.log.

Forty lines scroll past, then it waits for more.

Press C-b d.

tmux prints [detached (from session learn)] and you are back at the plain shell.

Run tmux attach -t learn.

The status line returns and tail is still running.

Attaching without a name

attach without -t picks the most recently used session that has no client — fine with one session, a guess with several.

Stuck on this one?

This is a live terminal. Typing goes to the machine, including Tab. Press Shift and Tab together to move focus back out to the page.

A real terminal, in this tab

about 15 MB, once

session learn

Done when

not started
  1. tail is running in window 0 of session learn before detaching— not done yet
  2. No client is attached to session learn— not done yet
  3. A client is attached to session learn again— not done yet
  4. tail is still running in window 0 of session learn after reattaching— not done yet