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?
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.
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 ...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With