Difference between revisions of "Make 'rm' move files to the trash instead"

From Tech-Wiki
Jump to: navigation, search
(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...")
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 
[[Category:Apple]]
 
[[Category:Apple]]
 +
'''[[Apple#Mac|Back to Mac]]'''
 +
 +
 +
Use this feature to be able to undelete any file if desired. Originally the command rm deletes permanetely.
 +
 
Put this at your ~/.bash_profile
 
Put this at your ~/.bash_profile
  

Latest revision as of 05:21, 22 July 2016

Back to Mac


Use this feature to be able to undelete any file if desired. Originally the command rm deletes permanetely.

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
}