How to close a tmux session

71

19

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?

ph3nx

Posted 2014-07-05T10:19:22.747

Reputation: 813

To detach from tmux (leaving process running): https://unix.stackexchange.com/a/174443/178412

– atomh33ls – 2019-07-17T11:39:01.633

Answers

98

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.

0xC0000022L

Posted 2014-07-05T10:19:22.747

Reputation: 5 091

37

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.

Ville

Posted 2014-07-05T10:19:22.747

Reputation: 1 692

1Or if you prefer using your prefix, ctrl + prefix followed by : and then type kill-session -t name or kill-session -t number. If you do this from within the session you want to kill reattach using tmux a. – Matijs – 2016-04-14T10:03:32.367

22

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.

FSchndr

Posted 2014-07-05T10:19:22.747

Reputation: 321

This is similar to the current accepted answer, can you go into a little more detail on why your answer is different? – Burgi – 2016-12-29T12:37:50.307

1No 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 for kill-session. – FSchndr – 2016-12-29T14:34:54.583

+1: This answer is also the only one with the helpful -a to destroy all other sessions. – AaronDanielson – 2017-05-24T13:53:43.680

This is the better answer. I wish this were on the top of the answers... – Blaszard – 2018-07-04T11:31:07.653