Trying to run this compand in terminal:

sudo chown -R yourid:yourgroup local

However, I have no idea what my ID and my group are, or where to find them. Any ideas?

6 Answers 6


On OS X, your primary group is always staff unless you or your user directory manager changed it.

What's a primary group? The primary group of a user is by default the owner of all files created by that user.

For the purposes of chmod on your computer, you can use either your numeric user ID (e.g. 501), or your account name (e.g. danielbeck). The latter is different from the user name you usually see in the UI (e.g. Daniel Beck).

You can determine your account name using any of the following:

  • It's the name of your home directory (unless you customized it) in Finder's title or side bar

  • Run whoami in Terminal – so a chown -R $(whoami):staff should suffice. You can also get your primary group with groups $(whoami) | cut -d' ' -f1.

  • Open System Preferences » Users & Groups, unlock the pane if necessary, right-click your user name (the single list entry in the Current User section), and select Advanced Options…. It's the field Account Name in the newly opened dialog window. This dialog also shows you your primary group.

  • Run id in Terminal for more verbose output. This will include your numeric user ID. It'll also list all groups you're a member of, not just your primary group. The first group is the primary one.

  • 10
    Instead of using whoami, you can use id in a oneliner that is compatible with posix shells and csh. chown -R `id -u`:`id -g` FOLDER
    – fd0
    Jul 4, 2015 at 10:18
  • If you use LDAP authentication your username won't necessarily be staff. Not on my work Mac OS X anyway. Jul 31, 2015 at 23:21
  • 1
    @Sridhar-Sarnobat I address this in the second half of the first sentence of my answer.
    – Daniel Beck
    Aug 1, 2015 at 10:28

Use the id command from the terminal. It will display your uid and the groups you belong to. For example, here is my output showing my user id (534), group id (20) and the groups I belong to (also 20).

uid=534(galuga) gid=20(staff) groups=20(staff)

This will show your userid.

$ id -u

This will show your group names. The group names are inside parentheses.

$ id
uid=502(whoami) gid=20(staff) groups=20(staff),702(com.apple.sharepoint.group.2),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh)

Would only comment if I could. I don't have enough karma on this site.

I have no idea why someone downvoted @callaginn, as he brings up a valid point.

The following methods are valid (and probably the best options for shell scripting):

id -u  # returns UID

id -un # returns username

id -g  # returns primary (a.k.a. effictive) GID

id -gn # returns primary Group Name

See man id for more options.

To answer this specific question if I was writing a script that would work in any environment, I wouldn't assume that the default group staff is in use and instead I would do the following if I was writing a script that could be run for any user (whether or not they modified their system):

chown "$(id -un):$(id -gn)" some_file

It's always better to be platform agnostic whenever possible (if it's not too much of a time tradeoff), as you will incur less technical debt later.

Please note that chown's -R flag should be used with the utmost confidence. You could really mess up your system (Although it is worth noting that Apple made it hard to do since they implemented System Integrity Protection).

Consider, for instance, if you were to chown -R 755 /var instead of chown -R 755 /var/www as root with System Integrity Protection disabled I believe that you would be in for it. I can't tell you what would break first, but it would break first on a Darwin system, but please take my word that it wouldn't be pretty.

Hopefully, someone finds this helpful.


An even shorter method for finding the primary group:

id -gn
  • 1
    This is the magic one. So much cleaner than groups $(whoami) | cut -d' ' -f1. Jun 2, 2020 at 21:12

in Terminal, go to ~/Documents and run ls -la. Your user name and group will be listed next to each of the files/directories.

It should look like this:

drwxr-xr-x  2 username usergroup  4096 Oct 17  2012 Templates
  • super easy and straightforward, thanks for the tip.
    – teradyl
    Oct 26, 2016 at 23:14

You must log in to answer this question.

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