Unable to remove file or change permission on mac as root. I cant remove files from /Library/Extensions/ even if i run bash script as root. 


I also tried to change flags with 

chflags -R nouchg
chflags -R noschg
Here is output for ls -l even after chmod -R 777:

drwxr-xr-x  3 root  wheel  96 Aug  7 12:25 FileProtect.kext
rm -rf returns following:

rm: /Library/Extensions/FileProtect.kext: Permission denied


What can be reason for such behaviour?
There are a 2 reasons I can think of why this file (well, directory) might not be deletable.


Check for the "restricted" flag. This is part of SIP, and you should be able to see it via ls -lO /Library/Extensions/FileProtect.kext. If following the group you see "restricted" then this file is flagged as being protected via SIP. This shouldn't normally be the case for a file under /Library/ but people do the weirdest things.
The kext itself is blocking the delete operation. As it's in /Library/Extensions, there's a reasonable chance it's loaded automatically. If it implements a kauth vnode scope listener or a MAC policy, it can arbitrarily deny file operations, including deletions.


In either case, the solution is to boot into the recovery environment and to delete it there.