Joel Uckelman on 18 Nov 2003 03:08:34 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[hosers-talk] script-fu for trash


I just wrote this for Sara, and it occurred to me that someone besides her
might find it useful:

If you're a bash user who frequently deletes your files by accident and
then wants them back (waaaaah!), here's a function you can append to your
~/.bashrc which will give you a trash bin:


del() {
   T="$HOME/.trash/$(date +'%s').$$"
   if [ ! -d $T ]; then mkdir -p $T || return 1 ; fi

   for i in $* ; do
      if [ -w `dirname $i` ] ; then
         D=$(readlink -f $i)
         mkdir -p $T/$D
         mv $i $T/$D
      else
         echo "del: $i: Permission denied" 1>&2
      fi
   done
}


So, 'del foo' will move foo to your ~/.trash. Of course, del never deletes
anything, so you will still need to use rm to clean out your trash.

_______________________________________________
hosers-talk mailing list
hosers-talk@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/hosers-talk