Undelete for UFS2?

David King dking at ketralnis.com
Sun Aug 13 02:57:10 UTC 2006


>> Lastly surely someone has implemented a trash folder mechanism for
>> freebsd... what is it called so I can look up how to install it?
>
> maybe something like:
> mkdir ~/.trash
> alias rm     'mv -iv \!* ~/.trash/'

The problem with that solution is that when you move to a new system,  
you assume that your files will go to trash and then OH NO

Better to do something like:
	alias del 'mv -iv \!* ~/.trash/'
and get in the habit of using 'del'

Or maybe a script called 'del' in your path that looks like (I use  
this one):

#!/bin/sh

DATESUFFIX=`date -u +%Y-%m-%d--%H.%M.%S` # All files deleted at the  
same time need the same serial
LOCATION=${HOME}/.Trash

if [ \! -d ${LOCATION} ]; then
     echo Creating $LOCATION...>&2
     mkdir ${LOCATION}
     chmod 700 ${LOCATION}
fi
if [ \! -z $SUDO_USER ]; then
     THE_USER=$SUDO_USER
else
     THE_USER=$USER
fi

for each in "$@"; do
     if [ -e "$each" ]; then
         NEWFILE=${LOCATION}/`echo "$each" | tr / _`.${DATESUFFIX}
         echo -n $each '->' ${NEWFILE}
         mv "$each" "${NEWFILE}"
         chown -R $THE_USER "${NEWFILE}"
         echo .
     else
         echo \"$each\" was not found >&2
     fi
done

if [ \! -z "$PS1" ] || [ \! -z "$PROMPT" ]; then
     printf "Your trash can has %s and %s inodes\n" `du -hcd0  
$LOCATION 2>/dev/null | tail -n 1 | awk '{print $1}'` `find $LOCATION| 
wc -l`
fi




More information about the freebsd-questions mailing list