Command line users: Have you ever wished rm would put stuff in the Trash instead of just deleting it? After accidentally running rm -rf Desktop one day, I decided it was time to stop really deleting stuff when I ran rm. So I wrote is a shell function -- this means that the actual /bin/rm executable works like normal; only when you run rm from Terminal do files get moved to the Trash. This means that programs (and scripts) which delete files won't be affected.
So how do you use this? Open Terminal, and edit ~/.bash_profile (this is a script which is run every time you open a Terminal). Run nano ~/.bash_profile from the command prompt if you don't have a preferred editor. Add the following lines at the bottom of the file:
function rm () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
done
mv "$path" ~/.Trash/"$dst"
fi
done
}
Save the file and exit. (Hit Control-X in nano; it'll ask if you want to save, press Y and hit Enter to accept the default filename.)
Now, close all open Terminals. Open a new one. You can verify that the function exists with set -- you should see Terminal echo the lines you added above. If you see those lines, then you can test it by creating a new file and then deleting it. (Your input is after the $ on the lines below.)
$ touch newfile
$ ls -l newfile
-rw-r--r-- 1 mas mas 0 Feb 22 19:12 newfile
$ rm newfile
Now open up your Trash; you should find newfile somewhere amongst the other stuff in your trash. So now you can rm files from the shell prompt without worry. There are a few caveats, though I believe these won't affect most people:
Mac OS X Hints
http://hints.macworld.com/article.php?story=20080224175659423