Mac – Directory with correct permissions is not writable

backuphigh sierrapermissiontime-machine

I installed high sierra on a new machine and then copied over some directories inside my home from my time machine external disk.

The backup was created with another machine and os version from a user having the same name of the one recently created on the new installation.

90% of the things went ok.

For unknown reasons some subdirectories of my home (copied from the backup) are not writable.

I have tried every possible combination of chmod commands, and in theory everything should work correctly:

  • cmd+i, general:
    • item not locked
    • item not shared
  • cmd+i, sharing and permission:
    • myuser: Read and Write
    • staff: Read Only
    • everyone: Read Only
  • stat shows:
    • Access: (0755/drwxr-xr-x) Uid: ( 501/ myuser) Gid: ( 20/ staff)
    • 501 is the correct id my current user

I think it's not a unix permission problem as the permissions should work as is.

I've also tried chflags nouchg my_folder with no luck.

Not sure what could cause this.

Best Answer

Write permission could be blocked by file/folder modes, user flags, non-ownership, Access Control Lists (ACLs) and/or extended attributes. Below are some commands which can fix these types of errors.

Note: I assume my_folder does not contain any symbolic links. If there are symbolic links, then these commands may need to be modified.

You can recursively change the folders mode to 755 (drwxr-xr-x) by using the command given below.

find my_folder -type d -execdir chmod 755 {} \;

You can recursively change the regular files mode to 644 (-rw-r--r--) by using the command given below.

find my_folder -type f -execdir chmod 644 {} \;

You can recursively remove user flags by using the command given below.

sudo chflags -R nouchg,nohidden,noopaque,dump,nouappnd my_folder

You can recursively change user ownership of the files and folders by using the command given below.

sudo chown -R $USER my_folder

You can recursively change the group of the files and folders to staff by using the command given below.

sudo chgrp -R staff my_folder

You can recursively remove any Access Control Lists (ACLs) by using the command given below.

chmod -RN my_folder

You can recursively remove any extended attributes by using the command given below.

xattr -rc my_folder

Often searching for locked files and/or folders can be useful. Below is a command for this.

find my_folder -flags +uchg -exec ls -dF {} \;