228

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?

fixer1234
  • 28,064
ph3nx
  • 2,383
  • 2
  • 14
  • 6

6 Answers6

244

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
  • 7,544
  • 10
  • 54
  • 94
103

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
  • 3,492
  • 3
  • 24
  • 20
57

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
  • 671
37

One of the best way to do this interactively is by pressing ctrl+b,w to go to window mode then add tag by pressing t. then press capital X to kill all tagged window...

enter image description here

this is apparent when you have mouse enabled. enter image description here

10

If you want to kill one session and all its windows and panes conveniently, just press PREFIXs. Then navigate to the session and hit x and confirm with y.

Killing a session using prefix s and then x y

(^A is my prefix)

You can also tag more than one session using t and then killing the tagged ones with X.

If you kill the current session, tmux will be exited as well. If you don't wish to exit, simply switch a different session before killing the session in question.

Martin Braun
  • 933
  • 2
  • 14
  • 24
-1

Unfortunately there does not appear to be a simple default keybind to do this, possibly because it's an action you might want to be careful about though this could be addressed with a confirm dialogue.

One way is C-x : to get the tmux prompt and kill-session

As @Vaisakh-k-m pointed out C-x w gives you an interface to select windows across multiple sessions which you can select with the arrow keys and t to toggle the tagged status then X to kill the tagged windows and y to confirm this action.

This way there is no need to type a command at the prompt (accessed with C-x :) kill-server kills all sessions not merely the current one

If you'd like a custom kill session keybind @user79262 suggests these additions 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

You can close the current window with: C-x (Your prefix Ctrl+a in the case of the OP, Ctrl+b by default) then & and confirm with y This shortcut kills the window but not the current session unless your are in the last open window.

If you run tmux ls you'll see that with C-x d the session is still running in the background. You can re-attach to these background sessions with tmux a -t <session> where session is a name number.