要修改Crontab中的定时任务时间,请按照以下步骤操作:
打开终端(Terminal)。
输入以下命令以编辑当前用户的Crontab文件:
crontab -e
如果你需要使用管理员权限编辑其他用户的Crontab文件,请使用以下命令:
sudo crontab -u username -e
将username替换为实际的用户名。
* * * * * command-to-be-executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday to Saturday; 7 is also Sunday)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
0 9 * * * command-to-be-executed
如果需要删除某个定时任务,只需删除对应的行即可。
保存并关闭Crontab文件。在大多数编辑器中,你可以按Ctrl + X,然后按Y,最后按Enter来保存更改。
重启Cron服务以使更改生效。这取决于你的操作系统和Cron实现。在大多数Linux发行版中,可以使用以下命令之一:
对于基于Systemd的系统(如Ubuntu、Debian、CentOS 8等):
sudo systemctl restart cron
对于基于SysVinit的系统(如较旧版本的CentOS、RHEL等):
sudo service crond restart
现在,你已经成功修改了Crontab中的定时任务时间。