1.创建文件
touch auto_mv.sh
2.编辑脚本文件
拷贝文件至新的目录中
find /home/bjcyh/log -mtime +14 -type f -name "*.log" | xargs mv -t /data/bjcyh/log
解释:
find /home/bjcyh/log -mtime +14 -type f -name "*.log"
查询“/home/bjcyh/log”目录下,超过14天,名称为“*.log”的文件。
“xargs”可能是起到传递参数的作用,暂时没理解清楚;
“mv -t /data/bjcyh/log” 移动文件指令;
3.添加定时器人物
crontab -e
* 14 * * * sh /xxx.sh
“* 14 * * *”标识每天14点执行;
“xxx.sh”为脚本文件路径;
4.重启crond服务
systemctl restart crond.service
5.检测
crontab -l