MacOS – How to delete a locked, invisible file in the Trash

command linedeletingmacosrootterminal

On an external disk (that contains a clone), the /.Trashes/501/Users/myusername/Desktop folder contains (within some subfolders) a locked invisible file that I cannot delete. The whole folder starting with 'Users' is visible in the Trash in my Dock.

I have tried:

  1. secure empty trash (it asks whether I want to delete locked files and I say yes)

  2. empty trash via Cocktail

  3. launched Terminal as root and went down to the file (admin user alone cannot cd into ./Trashes)

  4. files has these properties: -rw——-@ 1 myusername myusername 4635 Mar 3 2010 int10923.ris

  5. rm asks me whether I want to override override rw——- myusername/myusername sappnd,arch,schg,hidden for int10923.ris?

  6. I say yes, and it answers: Operation not permitted

  7. a get info on the file (in the Dock trash, first enabling viewing of invisible files for the Finder) shows it as locked but unchecking the box, it immediately re-checks itself, it permissions are myusername Read & Write, everyone No Access, trying to change that immediately reverts back to its previous state

  8. trying chflags nouchg or chflags dump on the file changes nothing (with Terminal running as root)

Best Answer

  1. The file could simply still be open by something. Use lsof <file> to see which process is hogging it, if any.
  2. Otherwise sudo rm -rf /.Trashes/501/Users/myusername/Desktop should get rid of it
  3. If that didn't work, try removing all the flags it's complaining about first: chflags nohidden,nosappdn,noarch,noschg <file>