Can't delete file even when using sudo
I've had this problem before, too. I believe this is because of System Integrity Protection. macOS protects some parts of the filesystem starting with El Capitan.
I think there are two ways to work around this.
- Disable System Integrity Protection
- Grant Full Disk Access to Terminal
For the first, restart your Mac, but hold down Command-R until you boot into Recovery Mode. Then on the menu, select Utilities then type csrutil disable
and press Enter. Reboot your Mac and try your rm
command again. When you're done, I suggest you go back into Recovery Mode and re-enable it (csrutil enable
).
For the second, open Security & Privacy in System Preferences. Click the Privacy tab, select Full Disk Access and add Terminal to the list of applications. You'll likely have to unlock that screen first by clicking the padlock at the lower left corner.
When I had this problem, I didn't know about the Full Disk Access trick and used the first option. I know it works. I just learned about the second option earlier today and I'm betting it does the trick, too.
Good luck!