253

I've got a tmux session where the window is too small because some user somewhere is connected.

How do I tell tmux to disconnect all connected users?

Cornelius Roemer
  • 3,772
  • 1
  • 24
  • 55
Drew LeSueur
  • 19,185
  • 29
  • 89
  • 106

3 Answers3

370

You can use <prefix> D (where prefix is C-b by default), to chose which clients to detach; it will also list they col/lines as well as the last used time. Note the uppercase D, i.e. Shift+d.

You could also use tmux's detach-client option

 detach-client [-P] [-a] [-s target-session] [-t target-client]
               (alias: detach)
         Detach the current client if bound to a key, the client specified
         with -t, or all clients currently attached to the session speci-
         fied by -s.  The -a option kills all but the client given with
         -t.  If -P is given, send SIGHUP to the parent process of the
         client, typically causing it to exit.

either from <prefix>:followed by detach [options] or on the command line inside tmux with tmux detach [options]

K Erlandsson
  • 13,408
  • 6
  • 51
  • 67
demure
  • 7,337
  • 3
  • 22
  • 17
  • 25
    ` D` be careful, the **majuscule D** is important here !! (I spend some frustrating time detaching my current client before realizing it :D ) – Simon C. Mar 23 '17 at 06:58
  • 6
    Thank you. I usually [Ctrl-b] [D] [up] [enter] – Drew LeSueur Apr 06 '17 at 16:23
  • 1
    I think I'm going to start using `prefix`+'D' so I don't forget about it. Worked like a charm. – user208145 Jul 30 '17 at 01:33
  • 17
    In a tmux session, `tmux detach-client -a` will detach all other clients except the current one. I often mistype `prefix-D` so I prefer this approach. I even have a function `detachothers () { tmux detach-client -a; `. – PEdroArthur Sep 23 '17 at 18:15
  • 3
    ...and in case you haven't come across the word before, "majuscule" means "upper-case". – larsks Apr 11 '19 at 14:33
  • 1
    Hmmm. I wonder how to exit from "Ctrl+D" mode? [ESC] does not work. I need it when I push Ctrl+D and see only one client (myself) – Alexander C Aug 24 '21 at 18:48
  • 2
    @AlexanderChzhen a single 'q' press does the trick for exiting the selection menu without choosing a session to end. – demure Aug 26 '21 at 16:32
183

tmux a -dt <session-name>

a=attach
d=detach other clients (so only you can attach to this session)
t=target
utapyngo
  • 6,946
  • 3
  • 44
  • 65
mrco
  • 1,995
  • 1
  • 10
  • 7
11

I'll break out @PEdroArthur's great comment into a separate answer since it directly answers the most common use case: "being within a tmux session and wanting to disconnect all other sessions"

Run this from within your tmux session:

tmux detach-client -a
Cornelius Roemer
  • 3,772
  • 1
  • 24
  • 55