Detach and come back
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.
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.
Here is what just happened.
C-b d runs detach-client. The server kept the session, its window and the tail process running with no client watching. attach-session -t learn connected your terminal to that session again; nothing inside it ever stopped.
- Detach this client and return to the outside shellC-bthend
- Attach to a session by name; plain tmux attach picks the most recent unattached onetmux attach -t name
Go further
tmux attachwith no-tattaches to the most recently used unattached session.tmux new -A -s learnattaches iflearnexists and creates it if not, so one command works either way.
- 1Detach with
C-b d, notexit.exitends the shell and takes the session with it. - 2Start the log with
tail -f ~/build.log, then pressC-b d. - 3Reattach with
tmux attach -t learn.
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
Alpine Linux and tmux 3.4 on an x86 emulator. Nothing to install, and no server behind it.
about 15 MB, once
Done when
not started- tail is running in window 0 of session learn before detaching— not done yet
- No client is attached to session learn— not done yet
- A client is attached to session learn again— not done yet
- tail is still running in window 0 of session learn after reattaching— not done yet