How to Change Owner of a Directory

94,977

Solution 1

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.

Solution 2

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.

Share:
94,977

Related videos on Youtube

Arc676
Author by

Arc676

Updated on September 18, 2022

Comments

  • Arc676
    Arc676 almost 2 years

    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.

  • mjturner
    mjturner almost 9 years
    Mac OS uses the same syntax. To execute the command as root, the easiest way on a Mac is to prefix it with sudo, so sudo chmod (you will be asked for a password with Adminstrator access).