Move file to Trash on Snow Leopard from Terminal

When you move a file to the trash OS X updates the .DS_Store file inside ~/.Trash with the "Put back" information. (See this question for more details)

In order to update this you would have to also update the .DS_Store file when you move a file to the Trash in Terminal.


I recommend installing the Ruby gem osx-trash.

How?

sudo gem install osx-trash

Usage?

Usage: trash [OPTIONS] <file> [<file> ...]
       trash [-e | --empty]
       trash [-l | --list]
Specific options:
    -e, --empty                      Empty the trash
    -l, --list                       List items in the trash
    -h, --help                       Show this message
    -v, --version                    Show version

Manipulate to the Finder's trash.

In the MacOSX SDK, there are the functions FSPathMoveObjectToTrashSync and related. It should be easy to write a Python (or whatever) script around it.

Edit: Just coded it. Can be found here: rm-trash.py.


You want the rmtrash program.

You can use it to add items to the Trash as if it was done in the finder.

Edit: I just tried using rmtrash to delete and recover. It works exactly like deleting from finder. Files show up in the Trash, can be dragged out and emptied exactly the same. Been using it since '06 or so.