Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having a little problem. I need to (from the command line) be able to see what users are logged in.

Here's the tricky part: I DO NOT want those users that have locked their screens and left their desktop to show up in my list.

I've tried doing these two things, but both of them show users that have locked desktops. Is there anything else I can do?


    last | head -n 1
share|improve this question
How is the program supposed to know when the user has locked screen? You don't even mention if they are using GNOME, KDE, or a custom environment; whether they have GNOME Screensaver, Xscreensaver, slock, or such. – grawity Mar 11 '12 at 17:30
They're using GNOME with GNOME Screensaver – davorb Mar 11 '12 at 18:24

who -Hu

will provide you a list of logged in users, and their idle times.

who -u

will forego printing the headers. To know whether it will report correctly for screen-locked users, I guess you'll have to test it. Here's the output from my system right now:

[mini-nevie:~] nevinwilliams% /usr/bin/who -Hu
USER          LINE     WHEN         IDLE       PID  COMMENT
nevinwilliams console  Apr 18 01:27  old        62
nevinwilliams ttys000  Apr 20 14:34 00:08    31675
nevinwilliams ttys001  Apr 20 14:35 00:04    31695
nevinwilliams ttys002  Apr 20 14:42   .      31758
[mini-nevie:~] nevinwilliams%

I ran the command from ttys002.

share|improve this answer
Using grep, you could then only show results that show results with an idle time less then that of your screen saver timeout period. That would, at the very least exclude all users who were timed out. What it wouldn't necessarily show would be those users who lock when they leave their workstation. – Usta Apr 20 '13 at 18:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .