4

When I try to copy some folders in /usr/local to a standard user's folder, I find there is a folder named 'local' I cannot delete, even with

# rm -rf local
rm: local: Operation not permitted

it tell me "Operation not permitted", but I do have the superuser privilege. Then I thought it may be something wrong with the flags, and the flag information is:

# ls -al
drwxr-xr-x  2 root    wheel   68 Oct 10 10:04 local
# ls -lO
drwxr-xr-x  2 root  wheel  sunlnk 68 Oct 10 10:04 local

It seems that I cannot change it's flag too. So what's the sunlnk means and what I can do to delete the empty folder?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
cjhang
  • 95
  • 7
  • 1
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Oct 10 '17 at 19:03

2 Answers2

3

'sunlnk' flag in MacOS due to the 'System Integrity Protection', so one can delete the file with 'sunlnk' flag only after disable the system integrity protection. The way to disable system integrity protection is rebooting computer to recovery mode, and enter the Utility>Terminal, in it type

# csrutil status
# csrutil disable

then reboot your computer. Remember to turn it on by csrutil enable again when you finish the things you want. For more detail steps, see https://www.howtogeek.com/230424/how-to-disable-system-integrity-protection-on-a-mac-and-why-you-shouldnt/

cjhang
  • 95
  • 7
0

If you don't get access to any of a file or a folder or any of Terminal command is not working for specific directory – it's time to recall macOS sandboxing and POSIX permissions!

Check the SIP status, so write the following command into the Terminal:

csrutil status

you'll get this:

/*   System Integrity Protection status: enabled.   */

If the status is enabled, you need to disable the SIP.

In order to turn off rootless/System Integrity Protection on macOS do the following steps:

  1. Be very careful about it ! Read about SIP here.
  2. Turn off your Mac (Apple > Shut Down).
  3. Hold down Command-R and press the Power button...
  4. Wait for macOS to boot into the macOS Utilities window.
  5. Choose Utilities > Terminal.
  6. Enter csrutil disable.
  7. Reboot.

To enable SIP again repeat steps 2-5 and enter this command in Terminal:

csrutil enable
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220