CentOS中的crontab(cron table)用于定时执行任务。它的基本语法格式如下:
* * * * * command-to-be-executed
- - - - -
| | | | |
| | | | ----- Day of the week (0 - 7) (Sunday to Saturday; 7 is also Sunday)
| | | ------- Month (1 - 12)
| | --------- Day of the month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
每个字段可以使用以下符号:
*:表示任意值,用于表示该字段可以匹配任何值。,:用于指定多个值,例如1,3,5表示在第1、3和5分钟执行任务。-:用于指定一个范围,例如1-5表示从第1到第5分钟。/:用于指定步长,例如*/5表示每5分钟执行一次任务。以下是一些示例:
0 1 * * * /path/to/command
15 * * * * /path/to/command
0 10 * * 1-5 /path/to/command
要编辑crontab文件,请在终端中输入crontab -e。要查看当前用户的crontab列表,请输入crontab -l。要删除当前用户的crontab,请输入crontab -r。