56

I use tmux when working on my desktop, and then if I want to work outside on my laptop I ssh over to the desktop and attach to the same session. Then when I close my laptop and go back inside, the session visible on my desktop is shrunken to show only the rows/columns available on my smaller laptop screen. Without opening up my laptop again, is there some way to force the laptop to detach from the session? Or at least to resize tmux to use all the available space on my desktop screen?

ceremcem
  • 605

3 Answers3

77

By default<prefix> D gives you a list of connected clients, and which ever you select is disconnected.

You can also use choose-client from the command line as an augment to tmux, or at tmux's command line <prefix> :

where prefix is C-b by default
NOTE: The 'D' is a capital D

demure
  • 6,200
  • Wow, it's kind of fun being able to detach myself! <prefix> D works great. – Paul A Jungwirth Jun 22 '13 at 02:54
  • The way you say that, and the phrasing of your question makes me wonder if you know about <prefix> d, the normal way of detaching? (before you close your laptop, you could just detach normally) – demure Jun 22 '13 at 03:00
  • 2
    Yes, I know <prefix> d, but I rarely do that because if I'm getting up for lunch or to stretch, I may not know whether I'm going to resume work from my office or the back porch. :-) – Paul A Jungwirth Jun 22 '13 at 04:55
  • In case this might be helpful for byobu users, it seems that de default tmux prefix under byobu is ctrl-a. – bli Oct 31 '19 at 09:00
  • When I do <prefix> D it just detaches my current terminal – Thomas Ahle Feb 03 '22 at 23:44
  • 6
    @ThomasAhle the 'D' is capital. A lower case 'd' detaches your current connection. – demure Feb 05 '22 at 00:31
  • Is there a way to know in that list which one is the "current client"? I don't want to detach myself :) – a06e Apr 22 '23 at 20:59
31

You can also do

tmux attach -t <tmux_session_name> -d

This will detach all other attached clients, and attach this new client.

10

If are not already inside a tmux session, you can detach the "other" clients like so:

tmux detach-client

from tmux man page:

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 specified 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.
wbg
  • 305