0
0
Linux CLIscripting~10 mins

tmux for persistent sessions in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - tmux for persistent sessions
Start tmux session
Run commands inside tmux
Detach session (leave running)
Logout or close terminal
Reattach to tmux session later
Continue work where left off
This flow shows how tmux starts a session, lets you run commands, detach safely, and reattach later to keep your work persistent.
Execution Sample
Linux CLI
tmux new -s mysession
# Run commands inside tmux
# Detach with Ctrl+b d

tmux attach -t mysession
Starts a tmux session named 'mysession', lets you detach and reattach to keep your session alive.
Execution Table
StepCommand EnteredAction TakenSession StateOutput/Result
1tmux new -s mysessionCreate new tmux session named 'mysession'Session 'mysession' activeNew shell prompt inside tmux
2# Run commandsUser runs commands inside tmuxSession 'mysession' activeCommand outputs shown inside tmux
3Ctrl+b dDetach from tmux sessionSession 'mysession' running in backgroundReturns to normal shell prompt
4logout or close terminalTerminal closed, tmux session persistsSession 'mysession' still runningNo output, session alive
5tmux attach -t mysessionReattach to existing sessionSession 'mysession' activeShell prompt inside tmux with previous state
6exitExit tmux sessionSession 'mysession' terminatedtmux session ends, back to normal shell
💡 Session ends when user types 'exit' inside tmux or kills the session explicitly
Variable Tracker
VariableStartAfter Step 1After Step 3After Step 5Final
tmux session statenoneactivedetached (running)attached (active)terminated
Key Moments - 3 Insights
Why does the tmux session keep running after I close the terminal?
Because at Step 3 you detached the session (Ctrl+b d), tmux keeps it running in the background even if the terminal closes, as shown in the execution_table row 4.
What happens if I don't detach and just close the terminal?
If you close the terminal without detaching, the tmux session usually ends. Detaching (Step 3) is necessary to keep the session persistent, as shown in the execution_table.
How do I get back to my work after detaching?
You use 'tmux attach -t mysession' (Step 5) to reattach and continue exactly where you left off, as shown in the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the tmux session state right after detaching with Ctrl+b d?
ASession terminated
BSession running in background (detached)
CSession active and attached
DNo session exists
💡 Hint
Check Step 3 and Step 4 in the execution_table under 'Session State'
At which step does the user reattach to the tmux session?
AStep 2
BStep 3
CStep 5
DStep 6
💡 Hint
Look for the command 'tmux attach -t mysession' in the execution_table
If the user never detaches and closes the terminal, what likely happens to the tmux session?
ASession terminates when terminal closes
BSession automatically reattaches
CSession stays running in background
DSession duplicates
💡 Hint
Refer to key_moments about detaching necessity and execution_table explanation
Concept Snapshot
tmux lets you create persistent terminal sessions.
Use 'tmux new -s name' to start.
Detach anytime with Ctrl+b d to keep session alive.
Reattach with 'tmux attach -t name' to continue.
Sessions persist even if terminal closes.
Exit session with 'exit' inside tmux.
Full Transcript
This visual execution shows how tmux creates a persistent session. First, you start a session with 'tmux new -s mysession'. Inside, you run commands as usual. When ready, detach with Ctrl+b d to leave the session running in the background. You can safely close your terminal; the session stays alive. Later, reattach with 'tmux attach -t mysession' to continue your work exactly where you left off. Finally, exit the session with 'exit' to end it. This process helps keep your work safe and persistent across logouts or disconnections.