Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnu screen: reattach all previously detached sessions

I have a few windows in a single screen session and then I want to detach my session. There is no problem with that.

But I can't find a way to restore all windows within my previously detached session. I can see that I can restore just one of them by ID.

But how can I reattach exact the same session environment with all the windows in it?

--

Updated:

If I type screen -d -r, this is what is says:

There are several suitable screens on:
    21074.pts-7.atx (05/29/2010 02:26:32 PM)    (Attached)
    3420.pts-3.atx  (05/29/2010 12:16:41 AM)    (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

How can I reattach all of them?

like image 740
Nikita Fedyashev Avatar asked May 29 '10 16:05

Nikita Fedyashev


People also ask

How do you reattach a screen session?

To start a screen session, you simply type screen within your ssh session. You then start your long-running process, type Ctrl+A Ctrl+D to detach from the session and screen -r to reattach when the time is right.

How do I resume a screen session in Linux?

Ctrl-a + r: It reattach a detached screen session.

How do I get out of GNU screen?

There are 2 (two) ways to leaving the screen. First, we are using “Ctrl-A” and “d” to detach the screen. Second, we can use the exit command to terminating the screen. You also can use “Ctrl-A” and “K” to kill the screen.


2 Answers

screen -d -r : Reattach a session and if necessary detach it first.

This will reattach your old session, will all its windows. If your session is still attached, it will detach it before attaching it to the current terminal. This is quite useful when for example you have kept your screen session in an ssh terminal on another computer.

like image 115
tonio Avatar answered Oct 24 '22 16:10

tonio


To reattach all previously detached sessions I use this little script.

#!/bin/sh
for line in `screen -ls | grep Detached |  awk '{print $1}'`; do
   xdotool key control+shift+t type "screen -r $line"
   xdotool key KP_Enter
done

"control+shift+t" happened to be a shortcut in my terminal for opening a new tab and it may be different shortcut in yours.

like image 36
Pawel Wodzicki Avatar answered Oct 24 '22 14:10

Pawel Wodzicki