To detach other clients from a tmux session, use Ctrl+b : followed by detach-client -a
to detach all other clients except yours. You can also specify a target client with detach-client -t /dev/pts/X
. Use list-clients
to see all connected clients before detaching.
detach-client -a
When multiple clients (terminal windows or users) are connected to the same tmux session, you might want to detach some or all of them. This is useful for managing shared sessions, freeing resources, or dealing with "stuck" connections.
Before detaching clients, you may want to see which clients are currently connected:
# List all clients connected to the current session Ctrl+b :list-clients # Or from the shell tmux list-clients -t session_name
This will show output similar to:
/dev/pts/0: session0 [80x24 xterm-256color] (utf8) /dev/pts/2: session0 [100x30 xterm-256color] (utf8)
Each line represents a client connection with its terminal path, session name, terminal size, and type.
To detach all clients except your current one:
# From within tmux Ctrl+b :detach-client -a # From the shell (detaches all clients from session_name except the calling client) tmux detach-client -a -t session_name
The -a
flag stands for "all except the current client."
To detach a specific client, you need to specify its terminal path:
# From within tmux Ctrl+b :detach-client -t /dev/pts/2 # From the shell tmux detach-client -t /dev/pts/2
Replace /dev/pts/2
with the actual terminal path shown in the list-clients
output.
If you have multiple sessions and want to detach clients from a specific one:
# From within tmux Ctrl+b :detach-client -a -s session_name # From the shell tmux detach-client -a -s session_name
This detaches all clients connected to the specified session, even if you're not currently attached to it.
Create a key binding for quickly detaching other clients:
# Add to your ~/.tmux.conf bind D detach-client -a
Now you can press Ctrl+b D (capital D) to quickly detach all other clients.
You can detach other clients while simultaneously switching to a different session:
# Detach other clients and switch to session_name Ctrl+b :attach-session -d -t session_name
The -d
flag detaches other clients, while the -t
specifies the target session to attach to. This is useful for taking control of a session that's being viewed by others.