List User Accounts on Mac from Command Line

Jul 5, 2016 - 19 Comments

Terminal in OS X

Mac administrators may find themselves in a situation where they need to display a list of all user accounts on a particular Mac by way of the command line. We’ll review a few methods for advanced individuals to list all accounts, both user and system, on any Mac with any version of Mac OS X system software.

A few preliminary basic approaches to this would be to access the login screen or to list the contents of the /Users directory, though if a user account is hidden then it would not display at the login screen and it’s equally simple to obfuscate a user from the /Users folder. Additionally, the existence of a name in the /Users/ directory is not foolproof, because you can delete a user account but preserve that users home directory. As a result, while those approaches may be appropriate for the casual Mac user looking to show what users they have on a computer, neither of those methods are particularly sufficient for most admin needs. But, by turning to the command line you can reveal all user accounts on a Mac, whether they are general user accounts of active users, admin accounts, as well as any system account.

How to List All User Accounts on a Mac from Command Line

Open the Terminal if you haven’t done so already, either on the local machine you want to list user accounts for, or by connecting to a remote Mac you’d like to see the user accounts on. We’ll then use the ‘dscl’ command, which works in all versions of Mac OS X system software.

View All Users & Accounts on a Mac

dscl . list /Users

The benefit (or trouble) with this approach is that it lists not only all user accounts on a Mac but it also shows every daemon and server process account. This would include usernames like Paul, Bob, Jill, but also daemons, system accounts, and process users like networkd, windowserver, daemon, nobody, root, _spotlight, _ard, _appserver, _iconservices, and many more.

If the complete list of users is thus undesirable, you can easily exclude all the _underscore daemon and process accounts by running the output through grep, as we’ll show next.

Show User Accounts Only

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

This command will filter out any of the _ underscore prefixed daemon users, which are not actually user accounts. You’ll get a much shorter list of user names returned as a result, but you’ll still find three user names included that are not typical user accounts, but are normal to be found on Mac OS X installs; daemon, nobody, and root.

Show All User Accounts, User Directories, & User GECOS Info on a Mac

Another approach would be to show and list a detailed account list of user accounts, the associated user account directory, and the user account GECOS info (which is usually a description of the account or a full user name). If you find yourself wondering what on earth some of the system accounts and process user ID accounts in the aforementioned lists are, this approach offers more details, including the gecos description for each account (for example, _qtss user is the QuickTime Streaming Server daemon)

dscacheutil -q user

The output of that command will be rather extensive, so you may want to pipe the result through more or less or redirect it into a text file for easier parsing.

There are likely other means of displaying all user accounts on a Mac, regardless of system version, if you know of an effective of informative method not covered here, do share it in the comments.


Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks


» Comments RSS Feed

  1. Thomas says:

    I love a good know-it-all. 😭😭

  2. Motti says:

    I wonder why nobody answers the non-command-line guys question with the first normal-mac-user answer: use the “Users and Groups” pane of the “System Preferences” to list, control and manage your Mac users and groups, if you’re not prepared for the unix-style mess that is the command-line.

    Furthermore, a “Mac” user is NOT a “unix/posix” user. It bases on it – but has much more (data, definitions, home directory, provisioning, profiles etc.) that is beyond the scope of these command-lines. trying to Create or Delete users from the command-line would really mess things up, and leave lots of orphaned junk on your Mac. DO NOT do that from the command-line unless you know very well what you are doing – and even then – that’s a bad idea. the only time I would do that, is if I need to control a remote machine and I only have an ssh login (terminal + shell) to the remote machine. any other way – Apple’s UI (and its automation) provide a better solution.

    Next – if you’re talking about those _prefixed_usernames as “process” or “daemon” you should also give at least a sentence about what these are (special users set up for background-processes that exist and run outside the context of any normal “Mac user”, and even when no Mac user is logged in. These ‘users’ have the minimal access and capabilities for the need of the processes running “under” them.

    Also, I didn’t really understand the last “GECOS Info” thing – please explain what it is, aside from providing the command-line. It also emits LOTS of information that would be nice if explained.

  3. Tom d says:

    I’ve tried to add a user from a basic bash line and single user mode and all variations of prompts dscl/ -create/User “etc” on my macbook and every time I get “command not found” any suggestions?

  4. Dicle says:

    I am confused, when i typed “dscacheutil -q user”. I got deamons and roots, and some of the other users were anonymous. I dont exactly know, what a deamon is, and what a root user is. Can someone please tell me why i do have more than 59 accounts on my mac, is it bad?

    • Mau says:

      Listing all accounts on a Mac will show many that are NOT users, but daemons etc. Those are for system processes, those are not user accounts. Root is super user, every Mac has root.

      User accounts are found in the /Users directory of Mac OS at your root Macintosh folder. That’s what someone is logging in as in most cases.

      I just wonder why you’re even looking at this if you’re confused by it, what do you aim to achieve? If you don’t know what any of this is, it’s not relevant to you. It’d be like reading about the specifics of rocket science or brain surgery, probably not relevant to you either.

  5. x0 says:

    Great post. Very helpful. I didn’t like the nobody account either. I found it in a dialogue box under privileges, groups, nobody = admin. Previous to I found users, my user name, and then under my selected user name it said admin. This made sense. I am using High Sierra v 10.13 .. Thanks again for the terminal commands, I can add them to my little OS X cheat sheet / notebook. Maybe I will write a book one day!

    • Tom says:

      nobody isn’t a hack.. it’s a special user for remote disk mounts (NFS). don’t try to remove it..

      while motti and mau may be a bit abrasive, they have valid points.. if you don’t fully understand this stuff, you best stick to the provided GUI interfaces. Some things may appear to be unix like, but a mac isn’t another linux variant. It’s nice it provides a command-prompt shell that makes it look like unix/linux, but, it really isn’t. So… put the sledge hammers away, and look around and learn, but probably best not to change a lot.

  6. LJ says:

    Excellent suggestions, thank you all. Can someone tell me why Groupmembership would state: root (and my computer name here). I never activated “enable root”.

  7. Rouabah says:


    How delete users account except two users account ? For example :

    I have 4 users account/
    I want to delete all users except : admin & usertemplate?

    What’s the good syntax?
    dscl . delete /Users/ !(admin | usertemplate) don’t work?

    What is a good syntax ?

    • Corey says:

      If you want to delete a user you need to do the following be in a root prompt or do sudo

      sudo dscl . -delete /Users/$username

      This will delete the user from the directory. Then if you want to delete the user folder you can do

      sudo rm -rf /Users/$username

  8. Ashraf Fahmy says:

    I have listed the users on my mac suspecting that someone had hacked my Mac as it had turned out to be very slow.
    I got many users with “_” before them, I got root, nobody daemon.
    That is in addition to my created users. Does this mean that everything is ok, or should I start worrying!

    • a Martin says:

      Not sure, but I think it’s an idea to run this and maybe share the results with me or someone who can ger a picture of the results:

      Maybe post at the Apple Discussions forum?

      If the computer is unusually slow it’s probably some process that’s running or the drive is reading and/or writing. Or a bad file system.

  9. sean says:

    Just checking something as I am not a command line user.
    When I use dscl . list /Users | grep -v ‘_’
    I get an account called “nobody”. Who is this and should I get rid of it?

    • Mark says:

      Absolutely NOT.

      NOBODY owns no files, is NOT in a privileged group, and has ONLY the permissions that any user would have (less the user directory, and control of those files) IOW, it’s a process account. It’s common on UN*X type systems.


  10. Alistaire Smialek says:

    If you have Fast User Account Switching enabled in Mac OS (X) you can see the list of possible user names on the Mac by clicking on the name or icon in the upper right corner.

  11. cthulhu says:

    I use a different trick for this to list admin account / admin users

    dscl . -read /Groups/admin GroupMembership

    WIll list all administrator accounts on the Mac

Leave a Reply


Shop on and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks


iPhone / iPad



Shop on Amazon to help support this site