Centos7.4 用shell创建以日期为名的多级文件夹

时间:2022-06-18 21:35:20

脚本如下:

currenttime=$(date +%Y%m%d%H%M%S);
echo "current time $currenttime";

currentyear=$(date +%Y);
echo "current year:$currentyear";

currentmonth=$(date +%m);
echo "current month:$currentmonth";

currentday=$(date +%d);
echo "current day:$currentday";

hostname=`hostname`;
echo "this is hostname:$hostname";
path= "/cloud/log/$currentyear/$currentmonth/$currentday"
if [ -d "/cloud/log/$currentyear/$currentmonth/$currentday/"  ];then
    echo "the dir[/cloud/log/$currentyear/$currentmonth/$currentday/ ] is exit"
else
    mkdir -p /cloud/log/$currentyear/$currentmonth/$currentday/
fi