How to close a tmux session
Solution 1
Press your prefix (e.g. Ctrl+A or B, which is the default) and then : and type kill-session
, then hit Enter. This will, as the name of the command suggests, kill the session.
Solution 2
If you want to close session other than the current session (and hence keep tmux running; closing the current session as in @0xC0000022L's answer, also closes tmux even if other sessions are available), do the following in one of the tmux windows:
# tmux ls
keepMe: 1 windows (created Wed Jun 24 14:20:15 2015) [171x41]
otherSession: 1 windows (created Wed Jun 24 14:22:01 2015) [171x41]
3: 1 windows (created Wed Jun 24 14:23:28 2015) [171x41]
(assuming here that you're on keepMe session)
# tmux kill-session -t otherSession
-or-
# tmux kill-session -t 3
This deletes the "otherSession" or session number 3, and leaves tmux running, assuming you didn't have "otherSession" or number 3 session selected when you deleted them.
Solution 3
TMUX Prefix (e.g. ctrl+b) + :kill-session
or
tmux kill-session
(could run either from the inside of a session or the outside)
Both styles of invocation can use the flags:
-t target-session
destroys the given session
-a
destroys all sessions but the given one or the one you are attached to
Running kill-session
from the outside of TMUX kills the last session you were attached to. -a
inverts that.
In the event, that you have more than one session running you could kill all sessions at once with: kill-server
.
ph3nx
Updated on September 18, 2022Comments
-
ph3nx over 1 year
I am using tmux to manage multiple terminal windows. Currently I have 2 windows open with multiple panes. I know that I have to use the prefix (for me it is ctrl+a) to enter commands.
How can I close the session from inside of tmux? What command would close the session (all windows and panes) and tmux at the same time?
-
Admin almost 5 yearsTo detach from tmux (leaving process running): unix.stackexchange.com/a/174443/178412
-
Admin almost 3 yearsOne very handy way to kill multiple sessions at once is first go to the overview window (with
Ctrl
+a
->s
) and then pressx
with the target section selected, followed byy
to confirm. No typing:kill-session
, no rebinding
-
-
Matijs about 8 yearsOr if you prefer using your prefix,
ctrl + prefix
followed by:
and then typekill-session -t name
orkill-session -t number
. If you do this from within the session you want to kill reattach usingtmux a
. -
Burgi over 7 yearsThis is similar to the current accepted answer, can you go into a little more detail on why your answer is different?
-
FSchndr over 7 yearsNo one pointed out, that you could close all sessions with the
kill-server
command. I also liked to provide a little more depth on the flags forkill-session
. -
AaronDanielson almost 7 years+1: This answer is also the only one with the helpful
-a
to destroy all other sessions. -
Blaszard almost 6 yearsThis is the better answer. I wish this were on the top of the answers...
-
alizeyn about 4 years
exit
can be used instead ofkill-session
too -
dgruending over 3 years
exit
will only close, e.g., the bash that tmux has opened. When you only have one panel open this may also close the window - not so for two panels open within one window. -
user79262 about 3 yearsHere are useful bindings just in case someone stumbles on this issue. Add the following to your
.tmux.conf
bind C-x confirm-before -p "kill other windows? (y/n)" "kill-window -a"
bind Q confirm-before -p "kill-session #S? (y/n)" kill-session
-
Faither over 2 years
-
Niing over 2 yearsIs it possible to use entire session name to kill the target session? I remember that
-t
will match on prefix of any length. -
Admin almost 2 yearsA better way (AFAIK the correct answer to the OP):
Ctrl
+B
, then&
and confirm withy