- 论坛徽章:
- 0
|
#!/bin/bash
#wds
#v5.0
#2007.11.18
#7717060.cublog.cn
to=$1
to1=$2
home=$HOME/.garbage
dtime=$(date +%M-%H:%M)
userpid=$$
size=$(du -sh $home|awk '{printf $1}')
size1=$(echo $size | grep M)
size2=$(echo $size | sed 's/M//g')
ipaddr=$(/sbin/ifconfig eth0 | awk '/inet /{print substr($2,6)}')
adminemail=7717060@163.com
if [ -n "$size1" -a "$size2" -gt 100 ]
then
echo "$home is $size" | mail -s '$ipaddr' '$adminemail'
fi
if [ ! -e "$home" ]
then
mkdir -p $home
fi
myrmi ()
{
echo -e "rm: remove directory '$to1'?\c"
read -r answer
if [ "$answer" = y ]
then
if [ -d "$to1" ]
then
echo "rm: remove idrectory '$to1'?"
else
if [ -e "$home/$to" ]
then
mv "$to1" "$home/$to1-$userpid-$dtime"
else
mv "$to1" "$home"
fi
fi
fi
}
myrmrf ()
{
if [ -e "$to1" ]
then
mv "$to1" "$home/$to1-$userpid-$dtime"
else
mv "$to1" "$home/$to1-$userpid-$dtime"
fi
}
myrm ()
{
if [ -d "$to" ]
then
echo "rm cannot remove '$to': IS a directory"
else
if [ -e "$home/$to" ]
then
mv "$to" "$home/$to-$userpid-$dtime"
else
mv "$to" "$home"
fi
fi
}
if [ "$#" -eq 1 ]
then
case "$to"
in
-i) echo "Try 'rm --help' for more informaction." ;;
-rf) echo "Try 'rm --help' for more informaction." ;;
-r) echo "Try 'rm --help' for more informaction'" ;;
*) myrm;;
esac
fi
if [ "$#" -eq 2 ]
then
case "$to"
in
-i) myrmi ;;
-rf) myrmrf ;;
-r) myrmrf ;;
*) echo "'rm --help' for more informaction."
esac
fi
if [ "$#" -gt 2 ]
then
for file in $*
do
mv $file "$home/"
done 2> /dev/null
fi
本命令支持
rm *
rm -r
rm -i
rm -rf 等, |
|