What to do if chmod/chown/rm commands result in "Operation not permitted" error

"Mac has many enhancements to Unix in the area of files. Ignoring the whole resource fork thing which is not used much anymore, there are:
  • the standard Unix permissions ugo rwx and so on. Normal Unix tools apply.
  • ACLs, viewable with ls -le and changeable with chmod [ -a | +a | =a ].
  • file flags viewable with ls -lO and changeable with chflags.
  • extended attributes, viewable with ls -l@ (attribute keys only) and changeable with xattr. (Note that there is no man page for xattr, but it's a simple program described with xattr -h.)


You can be denied operations on a file because of Unix permissions, ACLs or file flags.
To fully unlock a file:
sudo chmod -N ugo+rw somefile # Remove ACLs and set allow everyone read-write permission
sudo chflags nouchg somefile

Note that if ls -lO shows that the schg flag is set, you have to get into single-user mode to unset it. I'm not going to get into that here as there are bigger questions about why the file has that flag set and why you are trying to mess with it and what the consequences will be."