Take the 2-minute tour ×

We used gnu screen a lot in the office and sometimes if I don't take note, I end up getting lost as to what screen session I already am in.

So my question is, how do you know what screen session you're in? Do you have a way to check?

CLARIFICATION: What I need to know is when I do a:

~$ screen -ls

and I see something like:

There is a screen on:
    4732.work_Sept42012     (Attached)
    3551.web01  (Attached)
    5521.mysql01 (Attached)
    1255.tomcat05 (Detached)
    3326.oracle15 (Attached)

 1 Socket in /tmp/uscreens/S-icasimpan.

How do I know if I am currently connected to any of the attached session?

Thanks in advance.

share|improve this question
See this answer from superuser.com –  Burhan Khalid Sep 3 '12 at 2:26
@BurhanKhalid this is a good point but I wonder if there is screen generated info you can query. +1 for giving a helpful response :) –  icasimpan Sep 4 '12 at 1:54
possible duplicate of How can I tell whether I'm in a screen? –  LopSae Feb 14 at 1:12

2 Answers 2

In addition to the sessionname screen command, screen sets the STY environment variable for processes it starts. You can check the value of this variable from a shell:

$ echo $STY
share|improve this answer


ctrl+a, :sessionname can be used to display the name of the current screen session.

Previous reply (with missinterpreted question):

I struggled with this too until I came across the wonderful hardstatus feature. With these two lines in my ~/.screenrc I get the following at the bottom of my screen sessions.

hardstatus alwayslastline
hardstatus string '%{= kG}%-Lw%{= kW}%50> %n*%f %t%{= kG}%+Lw%< %{= kG}%-=%D %M %d | %C:%s %A %1`%{-}'

enter image description here

What I am looking at here is a screen session on my local computer with three windows (bash, mumble, kalkyl). In the active window called mumble I am connected to another computer over ssh on which I am running another screen session with three windows (top, auto, bash). I can see see all windows in both sessions and keep track of where I am.

share|improve this answer
The purpose of having the current time in the status line is to see whether the connection is live, i.e. if I get disconnected the time freezes. –  Backlin Sep 3 '12 at 9:20
your reply was helpful and I actually used it now in my .screenrc. I've added clarificatory statements to my question that you might have an answer too. +1 point for you too for being helpful :) –  icasimpan Sep 4 '12 at 1:52

Your Answer


