How to recursively change sharing/permission of a folder in Mac OS X

58

14

Is there any Mac OS X tools or scripts which allow me to change sharing/permission properties of files and subfolders in a folder recursively? For example, to let everybody or a specific user able to read and write, read only, or write only.

puri

Posted 2009-10-08T04:13:50.557

Reputation: 1 091

Answers

79

Try the chmod command. For example, if you have a directory name mydir, the following command will enable read/write for that mydir recursively.

$ chmod -R +rw mydir

For more information:

$ man chmod

Hai Vu

Posted 2009-10-08T04:13:50.557

Reputation: 4 824

1Does not work for me, only apply to the main folder, not the sub-folders. – delphirules – 2016-06-17T16:12:02.730

19Good answer, bad example. When adding read and/or write access to folders, you need to add execute ("x", aka search) access as well, or else the r/w are kinda useless. On the other hand, you don't generally want to add execute to files. When doing a recursive change, you're operating on a mix of files and folders. The answer is to use chmod's "smart execute" (capital X) feature: chmod -R +rwX mydir will add execute only when it makes sense. – Gordon Davisson – 2009-10-09T00:07:03.720

Gordon: Great observation. However, a directory normally has the x turns on, unless the user does something funky to turn it off. – Hai Vu – 2009-10-09T06:33:23.330

1Depends on the initial permissions. If you take a look in a default-config Mac home folder, for example, you'll see for most of the folders (Desktop, Documents, Library, etc) the owner has full (rwx) access to everything, but group and others have no access (no read, write, or execute). If you're adding read or write for group or others to one of these folders, you need to add execute as well. – Gordon Davisson – 2009-10-09T19:18:21.783

29

Select the root folder that you'd like to work with and open the Inspector (CMD-i or right click and "Show Info"). The bottom panel is where you can manage permissions.

Add and remove permissions to the list there. To apply the same permissions recursively to every subfolder, click the cog and select "Apply to Enclosed Items..."

Note: I noticed that the "Apply to Enclosed Items..." is greyed out when the little lock icon at bottom right hand side of window is locked. If this is the case just click on the lock to unlock it by entering your credentials and then try again with "Apply to Enclosed Items..."

gregsabo

Posted 2009-10-08T04:13:50.557

Reputation: 391

While generally useful, it won't accomplish what's asked for. It replaces permissions in subdirectories, instead of e.g. adding a user to all of them, no matter what the permissions were before. – Daniel Beck – 2011-01-04T16:29:10.350

@DanielBeck you're wrong, it applies all elements of permissions, chmod and chown this is the correct 'mac' way to do it – Rob – 2011-12-02T10:43:33.913

i just tried this answer (on a test folder) and it did not work correctly: since a folder is typically 'executable', that bit was also set on all enclosed files, which is wrong. i just wanted to change user and group. – flow – 2013-11-12T21:44:04.700

12

You want to use the chmod and chown commands.

If I remember correctly, you can change the permissions like this:

chmod -R +a "joshhunt allow read" /some/file/or/folder/
chmod -R +a "Guest deny read" /some/other/folder/
chmod -R +a "Guest deny write" /some/other/folder/

For more details one these commands, look up their respective man pages in Terminal:

man chmod
man chown

Josh Hunt

Posted 2009-10-08T04:13:50.557

Reputation: 20 095

1Best way for when trying to specify permits for a particular user – megalucio – 2017-10-09T01:36:18.783