How do I do a find or du without getting permission denied errors

Typical example:

sudo du -xm /System/Volumes/Data | sort -n -o .all-du                                          
Password:
du: /System/Volumes/Data/Library/Caches/com.apple.aned: Operation not permitted
du: /System/Volumes/Data/private/var/networkd/db: Operation not permitted
du: /System/Volumes/Data/private/var/db/appinstalld: Operation not permitted
...

This question asked how to filter them out but I would like to figure out some way to gain permission to search everything on my disk. I don't plan to muck with Apple's private stuff directly but it might help me to figure out what I can do to free up the space.

The du command is just an example. I have the same problems with find and ls and any other command that tries to inspect protected areas on the disk.


Solution 1:

If a command running with sudo throws Operation not permitted, that usually means that the file in question is protected by SIP.

SIP can be disabled easily, here are the instructions from the Apple website linked above:

To disable SIP, do the following:

  1. Restart your computer in Recovery mode.
  2. Launch Terminal from the Utilities menu.
  3. Run the command csrutil disable.
  4. Restart your computer.

Note that Apple recommends to re-enable SIP as soon as you finish your privileged task:

Warning

Disable SIP only temporarily to perform necessary tasks, and reenable it as soon as possible. Failure to reenable SIP when you are done testing leaves your computer vulnerable to malicious code.