一个自己写的脚本,留作参考

 1#!/bin/bash
 2size2free=3 #G
 3n=0
 4m=0
 5KB=0
 6sizecounter=0
 7tempfile=~/.attach.tmp
 8echo "Listing files.Please wait."
 9ls -lu --block-size=--time-style=+%Y%m%d%/home/www/attach/ | grep '^-r' > $tempfile
10sort -gk 6 $tempfile -$tempfile
11for sizetmp in $(cat $tempfile | awk '{print $5}' | sed 's/K//g')
12do
13((KB=size2free * 1048576))
14if [ $sizecounter -lt $KB ];then
15   ((n++))
16   echo "$sizecounter"
17   ((sizecounter+=sizetmp))
18fi
19done
20echo -e '\E[1;31;43m'"###################file to del######################"
21head -n"$n" $tempfile
22echo -"###################file to del######################";tput sgr0
23echo -ne '\E[1;31m'"Would you really wanna del these files?? ";tput sgr0
24echo -ne '\E[1;33m'"===> [";tput sgr0
25echo -ne '\E[1;31m'"yes";tput sgr0
26echo -ne '\E[1;33m'"/";tput sgr0
27echo -ne '\E[1;32m'"no";tput sgr0
28echo -ne '\E[1;33m'"]";tput sgr0
29
30((sizetmp=sizecounter))
31((sizecounter=0))
32read yesno
33if [ "$yesno" = "yes" ]; then
34
35((m=n))
36while [ $n -ne 0 ]
37do
38echo ""$(cat $tempfile | cut -51- |head -n1)" DELELTED!"
39#rm ""$file2del""
40sed -i '1d' "$tempfile"
41((n-=1))
42done
43((sizecounter=sizetmp))
44fi
45echo -e '\E[5;31m'"$m files deleted total $sizecounter KB $(echo "scale=3;$sizecounter/1024"|bc) MB $(echo "scale=4;$sizecounter/1048576"|bc) GB";tput sgr0
46######################################################

注意 (())内部的变量为兼容csh而设定,不用加$引用变量

posted @ 2009-03-29 19:54  Auxten  阅读(187)  评论(0编辑  收藏  举报