What’s the equivalent terminal command for removing users/groups from a folder recursively

finderpermissionterminal

When I remove a user or a group permission from a folder and all its children files and folders, this is what I do:

  • Right click the folder
  • Click "Get info"
  • Unlock the padlock (typing my admin password)
  • Remove users and or groups
  • Press "Apply to all enclosed items" and confirm

How can I do this from the terminal?

Best Answer

You would use the chmod command, with the -a flag to delete access control list entries, and the -R flag to do so recursively.

For example:

$ chmod -R -a "admin allow read" foldername

would make all files in foldername read-only for the admin user (because you're removing the "allow read" property for "admin".

$ chmod -R -a "joe allow delete" foldername

would prevent user joe from deleting any file in foldername.

To add properties back, use +a instead of -a.

For more details and examples, see the chmod manpage, or this article.