How to Change Owner of a Directory

EDIT: The problem was that Apple uses permissions to mark backups and prevents you from modifying them (probably a security feature). By using chmod -RN <dir> I removed ACL data from all the folders with important data and that allowed me to make myself the owner and apply the appropriate permissions.

Original question
I have an extremely large backup (>700GB) that now has the wrong permissions (my UID changed during clean install, long story) and I need to change them. The time-consuming option is to manually go through each folder and change the permissions but that will take ages.

I want to use chown to make myself the owner of all my important data and then use chmod 700 on all those folders to give rwx permissions to only me.

The ideal solution is some method of using find to recursively look for folders matching a regex (my current one is .*/[DCV].*|Pictures|M[ou].*) and then make my UID the owner and set the permissions to 700.

The important bit that I can’t grasp:
However, when I try to run chown Me DirectoryName I get chown: DirectoryName: Operation not permitted.

Everything I find is related to changing the permissions of a file and not a directory. Maybe I’m looking at this the wrong way?
Something tells me there isn’t a way of giving my UID rwx and --- to everyone else.

How can I achieve this? I’m running Mac OS X 10.10.3.

I know that this is a UNIX/Linux forum (and I’m running Mac) but this question is a lot more about using the shell, chown, chmod, and permissions and any solutions posted here will be applicable to any UNIX-based OS. It would be preferable if the posted solutions will make my older backups reappear in Time Machine.

Thanks to all who have promptly replied, but chown just doesn’t seem to work on directories for some reason. Is the fact that this is a .sparsebundle disk image on a network drive relevant? I assumed it would be the same as on any external drive.

Asked By: Arc676

||

I may have misunderstood. But you can recursively use chmod and chown eg.

chown -R username:username /path/directory

To recursively apply permission 700 you can use:

chmod -r 700 /path/directory

Of course the above is for Linux so not sure if mac osx is the same.

EDIT: Yea sorry forgot to mention you need to be root to chown something, I just assumed u knew this…my bad.

Answered By: dakka

try as root

 find wherever -type d -name ... -exec chown Me {} ;

where

  • -type d apply to dir only
  • -name ... your regexp
  • -exec chown Me {} ; use chown on find dir.

you must be root to chown.

Answered By: Archemar
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.