Linux crond scheduled task to delete files or folders

Do timing tasks based on centos7.9

Script: cleandata.sh

vi cleandata.sh

#!/bin/bash

#在/data/center_messagebuss/video/查找超过180天的文件夹并删除

find /data/center_messagebuss/video/ -mtime +180 -type d | xargs rm -rf

Add executable permissions and move to the /data directory

cp cleandata.sh /data/cleandata.sh

chmod +x /data/cleandata.sh

Add a scheduled task to execute the script at 3 am every day

crontab -e

0 3 * * *  /data/cleandata.sh > /dev/null 2>&1

#Restart crontab timing task service

service crond reload  

If an error is reported, use systemctl reload crond

service crond restart  

If an error is reported, use systemctl restart crond

Remark:

-mtime +180 : greater than 180 days

d: folder

f : file

Guess you like

Origin blog.csdn.net/qq_30381077/article/details/131933415