Trying to delete the following file: ~/Library/Cookies/HSTS.plist, but MacOS won't let me do it even when using sudo.

I just switched to Mac (was using Ubuntu before) and I'm probably missing something obvious. I'm using MacOS Mojave 10.14.1. What could be wrong?

sudo rm -f ~/Library/Cookies/HSTS.plist
rm: /Users/dima/Library/Cookies/HSTS.plist: Operation not permitted

I can't run ls on the folder files:

ls -la ~/Library/Cookies/
ls: : Operation not permitted

Output of ls -lde@ ~/Library/Cookies:

drwx------@ 11 dima  staff  352 Dec 11 23:03 /Users/dima/Library/Cookies
    com.apple.quarantine     -1

I found out I can delete the file using Finder, but not using command line. Why is that?

  • 1
    Can you run an ls on the file and directory?
    – Alex
    Dec 10 '18 at 15:33
  • 2
    Welcome to Ask Different :) Go to Finder → Go To Folder... in Menu bar. Enter ~/Library/Cookies. This will open Cookies folder in Finder. Simply select the file and try deleting it by pressing Command + delete key.
    – Nimesh Neema
    Dec 10 '18 at 15:47
  • Thanks @Alex, I edited my question to include additional info
    – Dima L.
    Dec 11 '18 at 20:05
  • Did you restore your system from backup? And can you run ls -lde@ ~/Library/Cookies as well to show the extended attributes and ACLs (if any)?
    – nohillside
    Dec 11 '18 at 20:05
  • 1
    If you'll run ls -ld@ ~/Library/Cookies, you'll see that the Cookies directory has com.apple.quarantine extended attribute set. That's what preventing you from accessing the file.
    – Nimesh Neema
    Dec 11 '18 at 20:11

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.

  1. Disable System Integrity Protection
  2. 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!

  • I have confirmed that the second option works. Thank you so much.
    – osexp2003
    Feb 12 '21 at 5:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .