温馨提示×

Linux Crontab时间格式怎样正确书写

小樊
38
2025-12-06 11:25:25
栏目: 智能运维

在Linux中,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)

以下是一些Crontab时间格式的示例:

  1. 每分钟执行一次命令:
* * * * * /path/to/command
  1. 每天凌晨1点执行命令:
0 1 * * * /path/to/command
  1. 每月1号凌晨1点执行命令:
0 1 1 * * /path/to/command
  1. 每周日凌晨1点执行命令:
0 1 * * 0 /path/to/command
  1. 每年1月1日凌晨1点执行命令:
0 1 1 1 * /path/to/command

注意:在Crontab中,你可以使用特殊字符,如*(表示任意值)、,``(表示枚举值)、-(表示范围)和/(表示间隔)。例如,*/15 * * * *`表示每15分钟执行一次命令。

0