How to close a tmux session

270,773

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.

Share:
270,773
ph3nx
Author by

ph3nx

Updated on September 18, 2022

Comments

  • ph3nx
    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
      Admin almost 5 years
      To detach from tmux (leaving process running): unix.stackexchange.com/a/174443/178412
    • Admin
      Admin almost 3 years
      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
  • Matijs
    Matijs about 8 years
    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.
  • Burgi
    Burgi over 7 years
    This is similar to the current accepted answer, can you go into a little more detail on why your answer is different?
  • FSchndr
    FSchndr over 7 years
    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.
  • AaronDanielson
    AaronDanielson almost 7 years
    +1: This answer is also the only one with the helpful -a to destroy all other sessions.
  • Blaszard
    Blaszard almost 6 years
    This is the better answer. I wish this were on the top of the answers...
  • alizeyn
    alizeyn about 4 years
    exit can be used instead of kill-session too
  • dgruending
    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
    user79262 about 3 years
    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
  • Faither
    Faither over 2 years
  • Niing
    Niing over 2 years
    Is it possible to use entire session name to kill the target session? I remember that -t will match on prefix of any length.
  • Admin
    Admin almost 2 years
    A better way (AFAIK the correct answer to the OP): Ctrl+B, then & and confirm with y