Deleting a single file from the trash in Mac OS X Snow Leopard

In earlier versions of Mac OS X one could delete a file from the trash by opening a terminal window and typing rm ~/.Trash/file_i_want_to_delete. See this previous post.

Unlike earlier versions in Mac OS X Snow Leopard one can "put back" a file from the trash into its original directory.

Will the rm trick still work? Testing shows it does delete the file but what happens to the "put back" information that specifies the directory from which the file was deleted?


Solution 1:

Mac OS X isn't updating the resource fork:

If you create a testfile on the desktop (plain text file), test.txt, check if the file has a resource fork by going into the terminal and executing:

cd ~/Desktop
ls -l test.txt
ls -l test.txt/rsrc

This lists the size of the textfile and secondly the size of the resource-fork (rsrc). If this rsrc size is 0, there is no resource-fork available for this file. If all is well, there is no resource-fork.

Put the file from the Desktop in your Trash folder. Then in the terminal do the following:

cd ~/.Trash
ls -l test.txt/rsrc

It still does not show a resource-fork here.

On to the .DS_Store file in the .Trash folder: Install a hex-editor (i.e.: http://ridiculousfish.com/hexfiend/ )

Put the test.txt file back. (and close the finder window with the trash folder.) Open the hex-editor from the terminal with the .DS_Store file:

cd ~/.Trash
/Applications/Hex\ Fiend.app/Contents/MacOS/Hex\ Fiend .DS_Store 

As you can see it's almost empty (turn off the option to show hexadecimal.) Close the hex-editor.

Trash the test.txt file and reopen the .DS_Store file in the hex-editor. Now you see the originating path of the file and the current filename in the trash folder.

So indeed the put-back information is put in the .DS_Store file.

Solution 2:

The "put back" informations are stored in the .DS_Store file in the Trash folder.

Every time you put another file into the Trash, Mac OS X updates the .DS_Store file.

If you delete a file manually (with the rm command), Mac OS X won't update the .DS_Store file in the Trash.

You could still remove manually files from the Trash, but the .DS_Store won't be deleted and will be sightly bigger over the time.
So you should sometimes delete the hole Trash.

Solution 3:

My guess would be that that information is stored somewhere in the file link text, be that the .DS_Store file or the resource fork of the actual file. Either way it isn't going to accumulate or build up too much.