Make 'rm' move files to the trash instead

From Tech-Wiki
Revision as of 19:17, 10 July 2016 by Fabricio.Lima (Talk | contribs) (Created page with "Category:Apple Put this at your ~/.bash_profile function rm () { local path for path in "$@"; do # ignore any arguments if "$path" = -* ; then : els...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Put this at your ~/.bash_profile

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
}