122

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?

2
  • 3
    To detach from tmux (leaving process running): unix.stackexchange.com/a/174443/178412
    – atomh33ls
    Jul 17 '19 at 11:39
  • 1
    One very handy way to kill multiple sessions at once is first go to the overview window (with Ctrl+a->s) and then press x with the target section selected, followed by y to confirm. No typing :kill-session, no rebinding
    – rtviii
    Jul 8 at 7:03
152

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.

3
  • 8
    exit can be used instead of kill-session too
    – alizeyn
    Mar 5 '20 at 8:53
  • 7
    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.
    – dgruending
    Oct 8 '20 at 8:43
  • 2
    Here 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
    – user79262
    Mar 31 at 23:15
58

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.

1
  • 2
    Or 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
    Apr 14 '16 at 10:03
37

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.

4
  • This is similar to the current accepted answer, can you go into a little more detail on why your answer is different?
    – Burgi
    Dec 29 '16 at 12:37
  • 1
    No 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
    Dec 29 '16 at 14:34
  • 2
    +1: This answer is also the only one with the helpful -a to destroy all other sessions. May 24 '17 at 13:53
  • This is the better answer. I wish this were on the top of the answers...
    – Blaszard
    Jul 4 '18 at 11:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.