Cannot remove an empty folder, got "Permission denied" even with sudo

Tried everything I could to remove an empty folder from my MacBook Air M3 running MacOS Sonoma 14.5.


  1. The start of the issue: cannot empty the Trash when the folder in. If I put the folder (named "cannot_remove") into Trash and try to empty it, I would get "The operation can’t be completed because the item “cannot_remove” is in use.". Tried to restart the system, go into safe mode and even turn off System Integrity Protection, none seem to work.
  2. From the terminal side (confirmed no hidden file inside, fixed permission, fixed ownership) (Worth noting though I can rename it, or move it around.):
yang@Yang-MacBook temporary % ls -la cannot_remove           
total 0
drwxr-xr-x  42 yang  staff  1344 Jun 26 22:40 .
drwxr-xr-x   7 yang  staff   224 Jul  3 10:38 ..
yang@Yang-MacBook temporary % sudo chown -R $(whoami) cannot_remove
yang@Yang-MacBook temporary % sudo chmod -R 755 cannot_remove      
yang@Yang-MacBook temporary % sudo rm -rf cannot_remove 
rm: cannot_remove: Permission denied

3. Also checked the info panel:


Any advice would be appreciated! Thanks!

MacBook Air 13″

Posted on Jul 2, 2024 7:44 PM

Reply
Question marked as Top-ranking reply

Posted on Jul 4, 2024 4:47 AM

Yep it's pretty funny.


And here's how I came out with this fix: Notice in the original post I mentioned that I could rename/relocate that folder, but cannot remove it. So I tried to move it to a USB drive (and format that drive afterwards). However during that attempt I got a notification like (cannot remember exactly): Cannot move because it's not downloaded to your machine. So I thought it might be something managed by OneDrive, and boom, it worked :)

Similar questions

5 replies
Question marked as Top-ranking reply

Jul 4, 2024 4:47 AM in response to TheLittles

Yep it's pretty funny.


And here's how I came out with this fix: Notice in the original post I mentioned that I could rename/relocate that folder, but cannot remove it. So I tried to move it to a USB drive (and format that drive afterwards). However during that attempt I got a notification like (cannot remember exactly): Cannot move because it's not downloaded to your machine. So I thought it might be something managed by OneDrive, and boom, it worked :)

Jul 3, 2024 4:21 AM in response to TheLittles

Thanks a lot for your reply and for suggesting a fix.


I somehow managed to remove it by moving it inside the OneDrive folder (it was originally located in the local drive, not in any cloud drive), and remove it from the OneDrive side. I still don't quite know what the reason for that issue in the first place, but at least I got rid of it :)

Jul 3, 2024 8:02 PM in response to Haoyu59

Haoyu59 Said:

"I somehow managed to remove it by moving it inside the OneDrive folder (it was originally located in the local drive, not in any cloud drive), and remove it from the OneDrive side. I still don't quite know what the reason for that issue in the first place, but at least I got rid of it :)"

-------


Excellent job troubleshooting!


Interesting.

OneDrive is a Microsoft product. So, it may have been opened with a MS app (of MS Office), pending deletion.

Jul 2, 2024 8:21 PM in response to Haoyu59

Haoyu59 Said:

"Cannot remove an empty folder, got 'Permission denied' even with sudo"

-------


Thank you of the screenshot.


IMPORTANT:  Back up your Mac with Time Machine prior to fiddling with all of this.


Ridding of a Non-Removable File:

Logging in as Root user may be the way to go about this. Just know to disable the root user after all is performed.


Set this Mac Up Anew.

I've been through this, and the only way was to backup my Mac with Time Machine Backup to a an External Hard Drive > set my Mac to factory settings > and then migrating it all over using Migration Assistant.

Jul 4, 2024 4:09 PM in response to Haoyu59

Haoyu59 Said:

[…]And here's how I came out with this fix:[…]

———-


Thanks for proving the solution.


Inform Apple of this Fix:

Do your Part: Spread the word if this fix to Apple via feedback. Apple wont get back to you directly, but the more they hear of this, the more they will know what is going on, and what needs to be fixed. Apple will know nothing of your findings, if you don’t report them to them.


To Provide Feedback:

  1. Go Here: Feedback - iPhone - Apple
  2. Select: "Bug Report" for the "Feedback Type"
  3. Comment: on your solution and how you came across it. Include the URL of this thread.
  4. Proceed from there as necessary

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Cannot remove an empty folder, got "Permission denied" even with sudo

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.