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

macmacososx-snow-leopardtrash

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?

Best Answer

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.

Related Question