Intosoft 工具
📅🔄

Cron Syntax Guide

Master cron expressions: the standard way to schedule recurring jobs in Unix, Linux, and many cloud services.

Cron Expression Format

*
Minute
0-59
*
Hour
0-23
*
Day
1-31
*
Month
1-12
*
DOW
0-6

* * * * * = runs every minute

The Five Fields Explained

1
Minute
0-59
Minute of the hour
0 = on the hour30 = half past*/15 = every 15 min
2
Hour
0-23
Hour of the day (24-hour format)
0 = midnight12 = noon9-17 = 9am to 5pm
3
Day of Month
1-31
Day of the month
1 = first day15 = middle of monthL = last day*
4
Month
1-12 or JAN-DEC
Month of the year
1 or JAN*/3 = quarterly6-8 = summer
5
Day of Week
0-6 or SUN-SAT
Day of the week (0 or 7 = Sunday)
0 or SUN1-5 = weekdays6,0 = weekends

Special Characters

CharNameExample
*Asterisk (Any)* * * * * = every minute
,Comma (List)0 9,17 * * * = at 9am and 5pm
-Hyphen (Range)0 9-17 * * * = every hour 9am-5pm
/Slash (Step)*/15 * * * * = every 15 minutes
LLast*0 0 L * * = last day of month
WWeekday*0 0 15W * * = nearest weekday to 15th
#Nth*0 0 * * 1#2 = second Monday
?No value*0 0 ? * 1 = every Monday

* Characters like L, W, # and ? are extensions not supported by all cron implementations. Standard Unix cron supports *, ,, -, / only.

Quick Reference

* * * * *Every minute
0 * * * *Every hour
0 0 * * *Every day at midnight
0 0 * * 0Every Sunday
0 0 1 * *First of every month
*/5 * * * *Every 5 minutes
0 9-17 * * 1-5Hourly during business hours
0 0 1 1 *Every New Year

Cron Shortcuts

@yearly / @annually= Once a year (Jan 1)
@monthly= First day of each month
@weekly= Every Sunday at midnight
@daily / @midnight= Every day at midnight
@hourly= Every hour at minute 0
@reboot= Once at startup

Shortcuts supported by most modern cron implementations

Important Notes

  • Timezone matters: Cron jobs run in the server's timezone. For cloud services, check if UTC is used.
  • Day-of-month vs Day-of-week: If both are set (not *), job runs when EITHER matches, not both.
  • Min resolution: Standard cron's smallest unit is minutes. For seconds, use specialized schedulers.
  • Sunday = 0 or 7: Both values represent Sunday in most implementations.