一个自己写的脚本,留作参考
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=K --time-style=+%Y%m%d%H /home/www/attach/ | grep '^-r' > $tempfile
10sort -gk 6 $tempfile -o $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 -e "###################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 -c 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######################################################
2size2free=3 #G
3n=0
4m=0
5KB=0
6sizecounter=0
7tempfile=~/.attach.tmp
8echo "Listing files.Please wait."
9ls -lu --block-size=K --time-style=+%Y%m%d%H /home/www/attach/ | grep '^-r' > $tempfile
10sort -gk 6 $tempfile -o $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 -e "###################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 -c 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而设定,不用加$引用变量