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.

19.4k 10 10 gold badges 43 43 silver badges 59 59 bronze badges asked Nov 1, 2011 at 12:57 codecowboy codecowboy 3,302 9 9 gold badges 37 37 silver badges 44 44 bronze badges

As a long time AIX user, I sure miss the system management commands they baked into their unix. lsuser would be nice to have for this purpose.

Commented Nov 1, 2011 at 14:25

8 Answers 8

dscacheutil -q user | grep -A 3 -B 2 -e uid:\ 5'[0-9][0-9]' 
103k 42 42 gold badges 219 219 silver badges 270 270 bronze badges answered Nov 1, 2011 at 13:32 4,182 2 2 gold badges 23 23 silver badges 24 24 bronze badges

I like this option. It returns a bunch of accounts beginning with an underscore, though. Any way to filter this out? e.g. _softwareupdate, _mysql

Commented Nov 1, 2011 at 14:13 Pipe the result through grep dscl . list /Users | grep -v ^_.* Commented Nov 1, 2011 at 14:20 Very cool! I'll have to remember this one. Commented Nov 9, 2011 at 21:58 This is such an easy one to commit to memory, too. Commented Jul 26, 2013 at 22:58 When I run this on Catalina, even with sudo , I only get myself. dscl . list /Users lists all users. Commented Nov 12, 2020 at 17:55

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

dscl . list /Users | grep -v '^_' 
answered Feb 9, 2013 at 12:29 621 5 5 silver badges 2 2 bronze badges That's precisely what @Mark said here. Commented Feb 9, 2013 at 12:36 what is the point of hidden accounts? Commented Jul 19, 2016 at 13:09 To see uid as well, use dscl . list /Users UniqueID | grep -v '^_' Commented Aug 27, 2017 at 11:10 What if the user isn't there? Commented Jan 13, 2019 at 2:54

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 .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.