Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How would I obtain the Users and Groups listed under System Preferences from a Mac through the terminal?

I've tried

dscl . list /users
dscl . list /groups

But they give me a list of system-ish users as well. I just want the users and groups I would see if I went into System Preferences and viewed them. Any help would be much appreciated. Thanks in advance.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

It's a bit more complicated than this, but for the most part the Users & Groups preference pane only deals with users and groups with IDs above 500. You can emulate this by filtering the lists that dscl generates. Here's a quick & dirty version, using awk to do the filtering:

dscl . -readall /Users UniqueID | awk '/^RecordName:/ {name=$2}; /^UniqueID: / {if ($2 > 500) print name}'
dscl . -readall /Groups PrimaryGroupID | awk '/^PrimaryGroupID:/ {id=$2}; /^RecordName: / {if (id > 500) print $2}'
share|improve this answer
    
The first one worked, the second line didn't return anything at all not even Admin or Standard User as listed in System Preferences. –  John Oct 5 '12 at 3:51
    
The second one is looking for groups, not users; if you haven't created any groups (other than the builtin system ones), it won't list anything. –  Gordon Davisson Oct 5 '12 at 5:56
    
Thanks for the help. Is there any specific documentation related to this. You mentioned a quick and dirty version. Is there a better, perhaps shorter, more concise version? –  John Oct 6 '12 at 3:45
    
I don't know of any documentation, and I'm not sure what additional complications (i.e. other criteria than ID number) there may be that this doesn't handle. A more complete version wouldn't be shorter, it'd probably be quite a bit longer. –  Gordon Davisson Oct 6 '12 at 4:00
    
What would a more complete version do exactly? Thanks for all the information. –  John Oct 7 '12 at 1:56
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.