Linux创建定时任务按时清除缓存

创建shell文件

cd /var/www/html
touch shell.sh

shell.sh文件写入

#!/bin/bash

#清除cache下的所有文件或者文件夹(并不包括cache)
rm -rf /var/www/html/test/cache/*

权限给予

chmod 750 shell.sh

创建定时任务

crontab -e  #创建定时任务
crontab -l  #列出所创建的定时任务
crontab -r  #删除定时任务

任务写入

# *号之间空格隔开
# 五个*号分别代表分,时,日,月,周。
#格式如下
* * * * * 要执行的操作 

#示例 每周一的两点时分,执行shell.sh文件指令
0 2 * * 1 /var/www/html/shell.sh