Linux tmux Command: Detach and Reattach Terminal Sessions
tmux is a terminal multiplexer that manages multiple windows and panes in a single terminal. It is useful for continuing shell work even if remote connections are lost, as you can detach a session and then reconnect to it.
tmux commands?
tmux has a hierarchy of sessions, windows, and panes. The default prefix key is Ctrl+b, and you press the next key after pressing the prefix key. Detached sessions are maintained as long as the tmux server is running, but they are not guaranteed to persist through a server reboot or tmux server shutdown.
Basic syntax
tmux [command] [option]
The installed implementation and options may vary depending on the distribution. Check the current system documentation with man tmux.
Examples
Starting a named session
By naming it, it is easier to distinguish what work it is later.
tmux new -s work
Checking the list of sessions
Find currently remaining sessions after detaching.
tmux ls
Reconnect to an existing session
Use the name given when starting.
tmux attach -t work
Detaching and Reattaching a Session
tmux separates the terminal connection from shell tasks. After creating a session, you can press the default prefix Ctrl+B followed by D to exit the screen, and the tasks inside the session can continue running.
tmux new -s demo tmux ls tmux attach -t demo
Example output of tmux ls after detaching (dates and status may vary):
demo: 1 windows (detached)
attach returns you to the screen of a detached session. If a session with the same name already exists, creating a new session may fail, so check with tmux ls first. It is useful for maintaining work even if the network to a remote server is disconnected, but if the server itself is rebooted, the standard tmux session will also disappear.
Main Options and Format
| Options/Format | Description |
|---|---|
new -s name |
Create a new session with a specified name. |
ls |
List sessions of the current tmux server. |
attach -t name |
Connect to the specified session. |
detach |
Detach the current client from the session. |
split-window |
Split the current window into panes. |
Precautions when using
In the default key bindings, pressing Ctrl+b followed by d detaches the session, c creates a new window, and % and " split the pane. You press the next key after the prefix key, not simultaneously. Some distributions may not have tmux installed, so first check whether the package is available.
Frequently Asked Questions
Does the tmux session always remain if the SSH connection is disconnected?
As long as the tmux server and remote system keep running, you can usually reconnect. It is not a feature that restores everything after a server reboot or session termination.
Official Documentation
You can check the exact behavior of options and implementation differences in the official tmux documentation.









