Home

Noppanit

05 Apr 2011

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.

function rm () {
  local path
  for path in "[email protected]"; 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
}

Til next time,
noppanit at 00:00

scribble