Mac OSX: Override Rm to Delete Files to .Trash

So silly of me I have just “accidentally” deleted my home directory T_T. There is a way to help that by override rm command to move file to .Trash.

Just copy this code to ~/.bash_profile and restart your terminal.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
}
Apr 5th, 2011

Comments