74

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.

  • 1
    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. – bmike Nov 1 '11 at 14:25
68

How about

dscacheutil -q user | grep -A 3 -B 2 -e uid:\ 5'[0-9][0-9]'
  • 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 – codecowboy Nov 1 '11 at 14:13
  • 9
    Pipe the result through grep dscl . list /Users | grep -v ^_.* – user151019 Nov 1 '11 at 14:20
  • Very cool! I'll have to remember this one. – daviesgeek Nov 9 '11 at 21:58
  • 5
    This is such an easy one to commit to memory, too. – Kelly Jul 26 '13 at 22:58
41

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

dscl . list /Users | grep -v '^_'
  • 3
    That's precisely what @Mark said here. – Emil Feb 9 '13 at 12:36
  • what is the point of hidden accounts? – SuperUberDuper Jul 19 '16 at 13:09
  • To see uid as well, use dscl . list /Users UniqueID | grep -v '^_' – Marián Černý Aug 27 '17 at 11:10
  • What if the user isn't there? – cameronroe Jan 13 at 2:54
10

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.

  • I like it, but it required sudo/root to work, std admin user got a permission error. dscl works for std admin. – JL Peyret May 12 '17 at 20:49
6

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.

4

JMTCW to recreate a command line friendly /etc/passwd equivalent (though not quite in the same order):

dscacheutil -q user |
    paste -d " "  - - - - - - - - |
    sed 's/^name: //;s/ [^[:space:]]*: /:/g'

Or if you prefer a space separated output (but parsing GECOS field will be a little more complicated:

dscacheutil -q user |
    cut -d: -f2 |\
    paste -d " "  - - - - - - - -
2

If no user home directories were moved then ls /users will do. Except it will also list directories like 'Shared'.

  • 2
    Never do this. There are much more than just Shared that can be there. – hamstergene Oct 25 '14 at 13:09
-3

You can also type:

who which tells you who's logged on, and where they're coming from. Useful if you're looking for someone who's actually physically in the same building as you, or in some other particular location.

w which tells you who's logged in, and what they're doing. Especially useful: the 'idle' part. This allows you to see whether they're actually sitting there typing away at their keyboards right at the moment.

You must log in to answer this question.

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