Attach to an already attached screen

on January 09, 2020. in Software, Development. A 1 minute read.

Today I ran into a strange error with screen. I was working on a remote server, executing commands in screen when my connection got dropped. I reconnected, wanted to reattach to my screen session with the usual -r option:

screen -r foo

But this greeted me with an error of:

There is a screen on:
	7608.foo	(Attached)
There is no screen to be resumed matching foo.

screen -ls confirms there is a screen session for “foo”. Apparently I came back to the server so quick that screen didn’t realize I got dropped from the session and it still thought I was there.

The solution is to run the screen command with -rd:

screen -rd foo

This tells screen to first detach the session and then reattach to it.

Another solution is to run the screen command with -x:

screen -x foo

This tells screen to reattach to an already attached session.

Happy hackin’!

Tags: screen.