在Debian系统中,Crontab的时间格式遵循以下规则:
* * * * * 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)
每个字段代表一个时间单位,从左到右依次为:分钟、小时、月份中的某一天、月份和星期中的某一天。你可以使用以下符号来指定时间范围:
*
:表示任意值,用于表示该字段可以匹配任何值。,
:用于指定多个值,例如 1,3,5
表示第1、3和5个单位。-
:用于指定一个范围,例如 1-5
表示从第1到第5个单位。/
:用于指定步长,例如 */2
表示每隔2个单位。以下是一些Crontab时间格式的示例:
# 每分钟执行一次命令
* * * * * command-to-be-executed
# 每天凌晨1点执行命令
0 1 * * * command-to-be-executed
# 每月1号凌晨1点执行命令
0 1 1 * * command-to-be-executed
# 每周日凌晨1点执行命令
0 1 * * 0 command-to-be-executed
# 每天上午10点到下午6点,每隔2小时执行一次命令
0 */2 10-18 * * command-to-be-executed
要编辑Crontab文件,请在终端中输入 crontab -e
命令。