sudo chown fails with operation not permitted
I have found similar questions here, but the answers provided to those questions do not resolve my problem.
If I do:
sudo chown <username> main.m
I get an operation not permitted error.
The general solution to prior errors was:
sudo chflags nouchg main.m
to clear a lock flag. However, after doing this, I still cannot chown the file. I have also tried:
chflags noschg main.m
in single user mode without any luck - I get an operation not permitted error.
If anyone has any thoughts, I would be interested.
Mac files can be protected in four three different ways that I'm aware of:
- Standard Unix ownerships and permissions like r/w/x for user/group/others that you see with
ls -l
and fix withchown(1)
andchmod(1)
. - File flags like
uchg
andschg
that you see withls -lO
and fix withchflags(1)
. -
The old Finder metadata "Lock bit" that you see withNever mind, this is mapped to theGetFileInfo filename
. You can also see the presence of the Finder metadata, but not its meaning, withls -l@
. You can fix it withSetFile(1)
.uchg
flag now. - Access Control Lists (ACLs) that you see with
ls -le
and fix with the ACL-related arguments tochmod(1)
.
So let's see what's up with your file by combining all those flags to ls
:
ls -lO@e main.m
It sounds like you already know how to deal with #1 and #2.
If you see an ACL (#4), you can fix it with the ACL-related arguments to chmod(1)
.
If you're still stumped, update your Answer with the output from that combined ls
command I suggested above, so we can see what's going on.