免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3945 | 回复: 2
打印 上一主题 下一主题

求linux“回收站”脚本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-11-29 14:32 |只看该作者 |倒序浏览
我记得再这里看见过 现在找不到了 哪位有心人 再发一次 谢谢

论坛徽章:
0
2 [报告]
发表于 2007-11-29 15:26 |只看该作者

论坛徽章:
0
3 [报告]
发表于 2007-11-29 15:38 |只看该作者
#!/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 等,
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP