keepcalculator

06 Numbers and Powers

List User Accounts Command Line Mac

Card No. 06·47963 · Updated · Standard formula, shown below

To list all user accounts on a Mac from the command line, the most direct command is dscl . -list /Users, which prints every account name. For a more detailed view including account type and home directory, use id or dscl . -read /Users/<username> for a specific user. This article explains the commands, what they show, and how to interpret the output.

Why Use the Command Line?

macOS provides a graphical way to see users in System Settings > Users & Groups, but the command line offers several advantages:

  • Faster – No clicking through menus.
  • Scriptable – You can use the output in shell scripts or automation.
  • More detail – See hidden system accounts, UIDs, and group memberships.
  • Remote access – Works over SSH.

The Basic Command: dscl

dscl (Directory Service Command Line) is the primary tool for querying the macOS directory services. To list all user accounts, run:

dscl . -list /Users

This outputs a simple list of account names, one per line. It includes both regular user accounts (like john) and system accounts (like _spotlight or root).

To get more details, you can add UniqueID and PrimaryGroupID:

dscl . -list /Users UniqueID PrimaryGroupID

This shows the UID and GID for each account. Regular users typically have UIDs above 500 (or 1000 on newer systems), while system accounts have lower numbers.

Understanding the Output

The output of dscl . -list /Users is just names. To see which accounts are “real” users, look at the UID. For example:

dscl . -list /Users UniqueID

Output might look like:

_amavisd      83
_analyticsd   94
_appleevents  97
...

Regular user accounts usually have UIDs starting at 501 (the first user) and increment. System accounts have UIDs below 500. To filter, you can use awk:

dscl . -list /Users UniqueID | awk '$2 >= 500 {print $1}'

This lists only accounts with UID ≥ 500, which are typically the interactive users.

Using the id Command

If you want to check a specific account, use id:

id username

This shows the UID, GID, and groups the user belongs to. For example:

id john
uid=501(john) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts)

Listing Only Human Users

To get a cleaner list of just the accounts that can log in, you can filter by the NFSHomeDirectory or check if the account has a password. A common approach is to look at the dscl output for the AuthenticationAuthority attribute, but that can be complex. A simpler method is to list users with a real home directory under /Users:

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

This excludes system accounts that start with an underscore. However, it still includes root and Guest. To exclude those, add more filters:

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

Common Problems and Solutions

Problem: Permission denied. Some dscl commands require sudo. If you get an error, prefix with sudo and enter your password.

Problem: The list is too long. Use grep or awk to filter. For example, to see only users with UID above 500, use the awk command above.

Problem: Need to see when a user was last logged in. Use last command:

last | head -20

This shows login history, not just account existence.

Alternative: Using System Profiler

Another way to list users is via system_profiler:

system_profiler SPHardwareDataType | grep 'Serial'

But that doesn’t list users. For user info, you can use:

system_profiler SPSoftwareDataType | grep 'User'

This is less reliable and not as detailed as dscl.

Frequently Asked Questions

How do I list only the users that can log in?

Use the UID filter: dscl . -list /Users UniqueID | awk '$2 >= 500 {print $1}'. This excludes system accounts and shows only interactive users.

What is the difference between dscl and dscacheutil?

dscacheutil is another directory service tool, but it’s more for flushing caches and querying specific records. For listing users, dscl is the standard.

How do I see if a user has admin privileges?

Check the group membership: dscl . -read /Groups/admin GroupMembership. If the username appears, they are an admin.

Can I list users from a remote Mac?

Yes, use dscl with a hostname: dscl hostname -list /Users. You’ll need appropriate access.

Why are there so many underscore accounts?

Those are system accounts for background services (e.g., _spotlight, _timed). They are normal and should not be deleted.

Conclusion

The command line is a powerful way to list and inspect user accounts on macOS. Using dscl gives you full control and detail. Always be cautious when modifying accounts—only read with dscl unless you know what you’re doing.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →