137

I've accidentally attached to a 2nd GNU screen session from within an existing screen session and cannot detach or issue commands to the inner screen. I remember figuring out how to do that before but completely forgot and would like to keep it as reference.

One way is to detach the inner screen by doing screen -dr from shell, but what is the key combination to do that from within screen itself?

0

4 Answers 4

182

ctrl-a a d

7
  • 5
    If you've customized screen's escape character to something other than Ctrl-A, then the key sequence will be quite different. :)
    – slacy
    Commented Mar 16, 2009 at 22:28
  • Yeah, you're on your own with that. <esc> a d may work; the man page is ambiguous, since it says that a sends the escape character, then clarifies that what it means by that is ctrl-A. So it's a crapshoot.
    – chaos
    Commented Mar 16, 2009 at 22:37
  • 4
    Thanks, there we go, that's exactly what I remembered too and when I told it to my co-worker who was having this problem, he said it didn't work. Of course, now I found out he was pressing ctrl-a, ctrl-a, d, instead of ctrl-a, a, d. Voted and closed.
    – Artem Russakovskii
    Commented Mar 16, 2009 at 23:32
  • 1
    @brandizzi: Have you tested this? Because I deeply suspect it is not the case, and that the sequence you would use is ctrl-t a d.
    – chaos
    Commented Oct 24, 2013 at 15:19
  • 1
    @chaos have you tested this? I tried it right now and, yes, C-t t d detaches the screen inside a screen. Can you try it? Just add escape ^Tt to your ~/.screenrc.
    – brandizzi
    Commented Oct 24, 2013 at 16:47
77

ctrl+a a will pass the escape sequence (ctrl+a) to the sub-screen.. So, ctrl+a a d will do ctrl+a d in the sub-screen (detaching it)

It works with any screen command, for example ctrl+a, a, c will create a window in the sub-screen

1
  • 4
    This one has a better explanation
    – Sgnl
    Commented Sep 21, 2017 at 0:54
7

In general, if you have a screen s3 within another screen s2 within another screen s1, you can execute a command ctrl-a d in the screen:

  • s1 by doing: ctrl-a d
  • s2 by doing: ctrl-a a d

  • s3 by doing: ctrl-a a a d

  • ...

0

Well, there is a hack for this. Just remotely de-attach the required screen by following command

screen -r -d screen_name or screen -rd screen_name
1
  • this one worked for me, I could get my attached screen back and detach it! Thanks
    – Peko Chan
    Commented Aug 29, 2022 at 5:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .