Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell whether I'm in a screen?

When using screen in linux, how can I tell if I'm in a screen or not? I could do exit and I'll exit a screen if I was in one, but if I wasn't, then I'll end up closing my terminal.

When doing screen -r, I could see if I have other screens attached, but how do I know if my current terminal is one of those attached screens?

like image 217
user8125 Avatar asked Mar 22 '11 14:03

user8125


People also ask

How do you know if I am in screen?

Method 2 - Using Screen prefix key To check whether we are in Screen session or not, simply press Ctrl+a and then Ctrl+t keys. This will show the time and host name if you are in Screen session.

How do you know in which screen I am Linux?

Worth noting that, if you're in screen and run screen -r , it will inform you that you're in a screen (or, if there are no screens, that lets you know you can't possibly be in one), and if you aren't in a screen, and become attached to one, you can simply type C-a (or whatever your screen command key is) + d to exit ...


1 Answers

Check $STY. If it's null, you're on a "real" terminal. If it contains anything, it's the name of the screen you're in.

If you are not in screen:

eric@dev ~ $ echo $STY eric@dev ~ $  

If you are in screen:

eric@dev ~ $ echo $STY 2026.pts-0.ip-10-0-1-71 
like image 167
jho Avatar answered Sep 29 '22 15:09

jho