1、create directory
!/bin/bash
for i in {1..12}
do
for y in {1..31}
do
if ((i < 10));then
if ((y < 10));then
mkdir -p /opt/logs/2020-0$i-0$y
else
mkdir -p /opt/logs/2020-0$i-$y
fi
else
if ((y < 10));then
mkdir -p /opt/logs/2020-$i-0$y
else
mkdir -p /opt/logs/2020-$i-$y
fi
fi
done
done
which looked like below
image.png
2、delete file
!/bin/bash
delete file of specifical directory and left only one month file
get current month
month=date +"%m"
remove 0 if month < 10
if (({month:1:1}
fi
iterator the specifical directory
for i in ls $1
do
rm=${i:5:2}
if ((${rm:0:1} == 0));then
rm=${rm:1:1}
fi
if ((rm > month));then
rm -f $1/$i/*
fi
done
image.pngimage.png
网友评论