我用的命令如下
find /backup/mx14/post/ -maxdepth 3 -type f -mtime +30 -print |awk -F/ '{print $1"/"$2"/"$3"/"$4"/"$5}' |head -100 |sort -u |xargs rm -rvf
for i in fmx1 mx1 mx2 mx14; do find /backup/$i/post/ -maxdepth 3 -type f -mtime +30 -print |awk -F/ '{print $1"/"$2"/"$3"/"$4"/"$5}'|sort -u |xargs rm -rvf; done
for i in mx4 mx5 mx25; do find /sdb/$i/post/ -maxdepth 3 -type f -mtime +30 -print |awk -F/ '{print $1"/"$2"/"$3"/"$4"/"$5}'|sort -u |xargs rm -rvf; done
for i in mx6 mx7 mx8 mx26; do find /sdc/$i/post/ -maxdepth 3 -type f -mtime +30 -print |awk -F/ '{print $1"/"$2"/"$3"/"$4"/"$5}'|sort -u |xargs rm -rvf; done
[root@gbackup1 ~]# for i in mx9 mx10 mx11 mx27; do find /sdd/$i/post/ -maxdepth 3 -type f -mtime +30 -print |awk -F/ '{print $1"/"$2"/"$3"/"$4"/"$5}'|sort -u |xargs rm -rvf; done
上面的命令一个个运行太麻烦了,我就把上面的命令综合到一起写了如下脚本:
#/bin/sh
fun_Del(){
find /sd$i/mx$j/post/ -maxdepth 3 -type f -mtime +30 -print |awk -F/ '{print $1"/"$2"/"$3"/"$4"/"$5}'|sort -u |xargs rm -rvf
}
for i in b c d e f g h
do
case $i in
b)
{for j in 4 5 25 ;do fun_Del();done;}
;;
c)
{for j in 6 7 8 26 ;do fun_Del();done;}
;;
d)
{for j in 9 10 11 27;do fun_Del();done;}
;;
e)
{for j in 12 13 15 28;do fun_Del();done;}
;;
f)
{for j in 16 17 18 31;do fun_Del();done;}
;;
g)
{for j in 19 20 21 29 30 ;do fun_Del();done;}
;;
h)
{for j in 22 23 24 ;do fun_Del();done;}
;;
esac
done