How to list all users that have terminal sessions, including screen sessions?
18,094
Solution 1
Try:
$ ps axno user,tty | awk '$1 >= 1000 && $1 < 65530 && $2 != "?"' | sort -u
This should tell you all UIDs with processes with a session terminal (like a window in screen). I use the UID to be weed out the 'system' users (like apache) and nobody (high UID), and ignore daemons.
Solution 2
You can try who, and the output of ps with a grep:
~$ ps aux | grep screen
And filter on user:
~$ ps aux | grep screen | grep $USER
(replace $user with the username).
Related videos on Youtube
Author by
Sander Marechal
Updated on September 18, 2022Comments
-
Sander Marechal over 1 year
I would like to have a list of all users that are active on my Linux system, including those who have running but detached screen sessions. The
who
command only shows me currently logged in users, but not users with detached screen sessions and the like.I was contemplating parsing the output of
ps
but that would also make a user show if if he has a cron job running.