I executed those two commands in terminal:



dscl . -read /Users/

and then they tell me two different results. The second one gave me a long list while the first one just showed my username on Mac.

When I google for "List users on Mac", most will tell me use the second one. However when I execute "man users", it shows me that this command is to "list current Users".

Could you tell me the differences?

Also, how do I execute a command as mysql user. The following command didn't work:

mkdir mysqldir --user mysql
  • 1
    I find it interesting that you got your username on your Mac for dscl . -read /Users/ because I get name: dsRecTypeStandard:Users which is what I would expect since it's trying to read a dsRecType (which is Users in this case, mind).
    – 2rs2ts
    Jul 17, 2013 at 19:07

3 Answers 3


dscl . -read /Users/ doesn't print anything particularly interesting; you probably mean dscl . -ls /Users, which prints a list of user accounts that are defined on your computer (including a great many normally-hidden system accounts). users, on the other hand, prints a list of users who are currently logged in on your computer (usually just you).

For your second question: you can use the sudo command to run commands as another user (e.g. sudo -u _mysql mkdir mysqldir). Note that this requires admin rights, and will ask you to enter your password for verification.


Get a list of all users (just their short names):

dscl . -list /Users

Get detailed user info on a particular user:

dscl . -read /Users/<username>

Get a particular value in a user's info:

dscl . -read /Users/<username> <key>

Examples of <key> are RecordName, RealName, UniqueID, and NFSHomeDirectory.

Get detailed user info on all users:

dscl . -readall /Users

Get a particular value in all users' info:

dscl . -readall /Users <key>

Hopefully you notice the difference between -list and -read. Additional goodies: -plist outputs as XML, -search lets you specify a key and value and you will get output indicating where that value is.

2rs2ts:~/ $ dscl . -search /Users RealName "Andrew Garrett"          [12:04:07]
2rs2ts      RealName = (
    "Andrew Garrett"

2rs2ts:~/ $ dscl -plist . -read /Users/nobody                        [12:05:29]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
        <string>Unprivileged User</string>

Of course, you can read the man pages to get more info.


The 'users' command only lists the currently logged-in users.

DESCRIPTION users lists the login names of the users currently on the system, in sorted order, space separated, on a single line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.