How can I list all user accounts in the terminal?

How can I list all local user accounts in Terminal (whether logged in or not?) The commands users or who does not provide this information. OS X version is 10.6.8.

I have seen this suggested command - dscacheutil -q group

But it only lists domain user groups and non-local accounts.


Solution 1:

How about

dscacheutil -q user | grep -A 3 -B 2 -e uid:\ 5'[0-9][0-9]'

Solution 2:

Try this one. I used it to find lost hidden account.

dscl . list /Users | grep -v '^_'

Solution 3:

User accounts since 10.6 are being managed by OpenDirectory. The backend files related to users for OpenDirectory are here:

/var/db/dslocal/nodes/Default/users

Executing ls * in this directory will enumerate all local users registered on the system. Executing plutil -p <file>.plist will allow you to read some properties for specified user account (i.e. current home directory path).

This is rather undocumented so I accept downvotes. However, this method can be used to inspect a system which is not running, and for which the user has only an offline disk image.

Solution 4:

dscacheutil returns more than just local users, for example any users I've queried Directory Services for also show.

I have found this more useful:

dscl . list /Users | grep -v "^_"

Although it also returns the likes of daemon, nobody and root.