How can I permanently delete folders from /var/folders/ situated in Trash?

Solution 1:

If you can’t delete the file because a process is holding it open you could try killing the process and then deleting the file. To find the process try the command below

lsof | grep [path_to_file]

Then kill each process by ID with

kill -9 [id]

For lsof to give you the PIDs the file must be open when lsof is actually executing. If it’s being opened and closed extremely quickly by one or more processes then this approach may not work

There’s another way that’s more OSX friendly/specific which is the following command

sudo fs_usage | grep [path_to_file]

Solution 2:

Killing the processes did not work for me. They kept respawning making it impossible to delete them.

The only way I could empty Trash, as briefly mentioned in the question, was to temporarily disable System Integrity protection (SIP).

If anyone else faces the same problem, these are the steps -

  1. You can disable SIP by following the numbered steps listed in this answer.
  2. After restarting your Mac, try opening Trash in Finder and clicking on Empty, which should hopefully delete the all of its contents.

Important: Do not forget to enable SIP after emptying Trash -

  1. Reboot your Mac in Recovery Mode and open Terminal, same as you did in Step 1 above.
  2. In the Terminal window, type in csrutil enable and press Enter.

  3. Restart your Mac.