MacOS – Deleting a ‘No such file or directory’ file

deletinghard drivemacosterminaltrash

I recently swapped out the CD drive on my Macbook Pro late 2011 for a hard drive. On that hard drive there were some files that I wanted to delete, as per usual I moved them to the Trash. Now that they're in there they can't be deleted because due a to a message saying that the "folder is currently still in use". I located the folder to be on my newly added hard drive in its /.Trashes/ folder. I accessed this directory through the terminal and executed the command "sudo rm -rf /.Trashes/", however upon execution the message "No such file or directory" is noted after each of the folders within. I keep reading that this problem is something to do with 32 bit and 64 bit architecture confusion but if I'm honest I don't really understand what this means.

There is no option to reinstate the folder in the Trash ("Put back") and I can't forcefully remove the folder on my new hard drive that is stopping it from being in use. I've also accessed my /.Trash/ folder on my OS hard drive and done the same command ("sudo rm -rf /.Trash/") with no such luck.

Does anyone have any idea how I can go about deleting these files so they're removed from my trash and new hard drive?

Best Answer

Removing a .Trashes directory or a .Trash directory is the wrong approach. You want to just remove the files and directories within your .Trashes or .Trash directory. Assuming your shell is bash you can list those file system objects in your .Trashes directory with find. In this example the secondary hard drive is named backup.

find /Volumes/backup/.Trashes/"$UID" ! -name "$UID"

If the results are the files you wish to delete then you can add -delete to the find statement. Please be very careful applying this option.

find /Volumes/backup/.Trashes/"$UID" ! -name "$UID" -delete

For files in your home folder's .Trash directory

find ~/.Trash ! -name .Trash -delete