Click to See Complete Forum and Search --> : script for rm-rf to move to trash


dalo
05-30-2003, 09:53 AM
I would like to create a script that when the 'rm-rf' command is executed, it will move the directory with a timestamp to a ~/.trash directory.

Any ideas on how to do this?

goon12
05-30-2003, 12:18 PM
Something long these lines might work
1. Create a script that does the moving and filenaming, save it some where you $PATH will read.
2. in your ~/.bashrc put this alias in

alias 'rm -rf'='<yourscriptname>'


As far as the time stamping the filename in the script, maybe something like this..

filename=trash_$(date '+%m%d')

#check if the dir ~/.trash exists
if [ -d ~/.trash ]
then
echo “Directory exists”
else
mkdir ~/.trash
fi
mv $filename ~/.trash



You should add some error checking to that, and what if they do it more than once in a day? My example will just put the month and day in the filename.

-goon12