14

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.

  • What kind of network drive? If it's NFS, there's a good chance it's exported with root_squash enabled, so you won't be able to perform root-only operations such as chown from the client. – Toby Speight Jul 13 '15 at 10:31
  • It's a HDD inside an Apple Time Capsule. Essentially it's a password-protected disk inside a WiFi base station. The only difference is that the HDD is connected to your computer via ethernet. There actually is a USB port but I've never used it. – Arc676 Jul 13 '15 at 10:36
  • Otherwise, the standard find . -user $other_uid -print0 | sudo xargs chown $USER should work. – Toby Speight Jul 13 '15 at 10:49
  • What network filesystem? df -hT <dirname> should tell you. – Toby Speight Jul 13 '15 at 10:51
  • @TobySpeight df -hT <dir> gives no output for a) the root directory of the network HDD b) the disk image inside the network HDD c) any folder on the network HDD. Perhaps the behavior you intended is implemented differently on Mac and on Linux? – Arc676 Jul 13 '15 at 11:41
23

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.

  • 1
    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). – mjturner Jul 13 '15 at 7:44
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.