定时任务:
[root@foundation21 ~]# systemctl status crond.service 首先查看定时服务是否开启

[root@foundation21 ~]# crontab -u root -e 建立定时任务,注意使用date命令看一下系统时间,有时候系统时间和真实时间是不一致
no crontab for root - using an empty one
crontab: installing new crontab
[root@foundation21 ~]# crontab -u root -l 查看定时任务
54 21 * * * /bin/rm -fr /mnt/file*
[root@foundation21 ~]# cat /var/spool/cron/root 查看自己编写的内容,到自己的定时之后就自动执行命令。
格式说明:
54 21 * * * /bin/rm -fr /mnt/file*
分钟 小时 天 月 周 意思是每天的九点五十四清空一次/mnt/目录下的file文件
[root@foundation21 ~]# crontab -u root -e 重新建立定时任务
crontab: installing new crontab
[root@foundation21 ~]# crontab -u root -l

本文介绍了在Linux环境中如何管理和配置定时任务。通过`systemctl`检查`crond`服务状态,使用`crontab`命令创建、查看、编辑和删除定时任务。详细解释了`cron`任务的时间格式,并展示了如何控制不同用户执行定时任务的权限,包括使用`/etc/cron.deny`和`/etc/cron.allow`文件进行黑白名单设置。
2888

被折叠的 条评论
为什么被折叠?



