一个自己写的脚本,留作参考
1
#!/bin/bash
2
size2free=3 #G
3
n=0
4
m=0
5
KB=0
6
sizecounter=0
7
tempfile=~/.attach.tmp
8
echo "Listing files.Please wait
."
9
ls -lu --block-size=K --time-style=+%Y%m%d%H /home/www/attach/ | grep '^-r' > $tempfile
10
sort -gk 6 $tempfile -o $tempfile
11
for sizetmp in $(cat $tempfile | awk '{print $5}' | sed 's/K//g')
12
do
13
((KB=size2free * 1048576))
14
if [ $sizecounter -lt $KB ];then
15
((n++))
16
echo "$sizecounter"
17
((sizecounter+=sizetmp))
18
fi
19
done
20
echo -e '\E[1;31;43m'"###################file to del######################"
21
head -n"$n" $tempfile
22
echo -e "###################file to del######################";tput sgr0
23
echo -ne '\E[1;31m'"Would you really wanna del these files?? ";tput sgr0
24
echo -ne '\E[1;33m'"===> [";tput sgr0
25
echo -ne '\E[1;31m'"yes";tput sgr0
26
echo -ne '\E[1;33m'"/";tput sgr0
27
echo -ne '\E[1;32m'"no";tput sgr0
28
echo -ne '\E[1;33m'"]";tput sgr0
29![]()
30
((sizetmp=sizecounter))
31
((sizecounter=0))
32
read yesno
33
if [ "$yesno" = "yes" ]; then
34![]()
35
((m=n))
36
while [ $n -ne 0 ]
37
do
38
echo ""$(cat $tempfile | cut -c 51- |head -n1)" DELELTED!"
39
#rm ""$file2del""
40
sed -i '1d' "$tempfile"
41
((n-=1))
42
done
43
((sizecounter=sizetmp))
44
fi
45
echo -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
######################################################
#!/bin/bash2
size2free=3 #G3
n=04
m=05
KB=06
sizecounter=07
tempfile=~/.attach.tmp8
echo "Listing files.Please wait
."9
ls -lu --block-size=K --time-style=+%Y%m%d%H /home/www/attach/ | grep '^-r' > $tempfile10
sort -gk 6 $tempfile -o $tempfile11
for sizetmp in $(cat $tempfile | awk '{print $5}' | sed 's/K//g')12
do13
((KB=size2free * 1048576))14
if [ $sizecounter -lt $KB ];then15
((n++))16
echo "$sizecounter"17
((sizecounter+=sizetmp))18
fi19
done20
echo -e '\E[1;31;43m'"###################file to del######################"21
head -n"$n" $tempfile22
echo -e "###################file to del######################";tput sgr023
echo -ne '\E[1;31m'"Would you really wanna del these files?? ";tput sgr024
echo -ne '\E[1;33m'"===> [";tput sgr025
echo -ne '\E[1;31m'"yes";tput sgr026
echo -ne '\E[1;33m'"/";tput sgr027
echo -ne '\E[1;32m'"no";tput sgr028
echo -ne '\E[1;33m'"]";tput sgr029

30
((sizetmp=sizecounter))31
((sizecounter=0))32
read yesno33
if [ "$yesno" = "yes" ]; then34

35
((m=n))36
while [ $n -ne 0 ]37
do38
echo ""$(cat $tempfile | cut -c 51- |head -n1)" DELELTED!"39
#rm ""$file2del""40
sed -i '1d' "$tempfile"41
((n-=1))42
done43
((sizecounter=sizetmp))44
fi45
echo -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 sgr046
######################################################注意 (())内部的变量为兼容csh而设定,不用加$引用变量
浙公网安备 33010602011771号