How cron expressions work
Cron is the time-based job scheduler built into Unix-like operating systems. Each scheduled task lives in a crontab (cron table) and begins with a five-field expression that tells cron exactly when to run the command. The fields are separated by spaces and are always read in the same order: minute, hour, day-of-month, month, day-of-week.
A job runs whenever the current time matches every field at once. Each field accepts a single value, an asterisk (*) meaning "every value", a comma-separated list (1,15,30), a range (1-5), or a step (*/5 for every fifth value, or 10-20/2 for every second value within a range).
*/5 and you get */5 9 * * 1 — every five minutes during the 9 AM hour on Mondays.The two "day" fields interact in a special way in real cron: when both day-of-month and day-of-week are restricted, most cron implementations run the job if either matches. This explainer treats both day fields as conditions to keep the description predictable.
The five fields at a glance
| Position | Field | Allowed values | Special |
|---|---|---|---|
| 1 | Minute | 0–59 | * , - / |
| 2 | Hour | 0–23 | * , - / |
| 3 | Day of month | 1–31 | * , - / |
| 4 | Month | 1–12 | * , - / |
| 5 | Day of week | 0–6 (0 = Sun) | * , - / |
Common examples
| Expression | Meaning |
|---|---|
| * * * * * | Every minute |
| */5 * * * * | Every 5 minutes |
| 0 * * * * | Every hour, on the hour |
| 0 0 * * * | Every day at midnight |
| 0 9 * * 1 | 9:00 AM every Monday |
| 0 0 1 * * | Midnight on the 1st of every month |
| 0 9-17 * * 1-5 | Every hour from 9 AM to 5 PM, weekdays |
Frequently asked questions
- What is a cron expression?
- A cron expression is a short string used by the cron scheduler on Unix-like systems to define when a job runs. The standard crontab format has five space-separated fields that together describe a repeating schedule.
- What do the 5 cron fields mean?
- In order they are minute (0–59), hour (0–23), day of month (1–31), month (1–12) and day of week (0–6, where 0 is Sunday). A job runs when the current time matches every field.
- What does '0 9 * * 1' mean?
- Run at minute 0 of hour 9 — 9:00 AM — on any day of the month, in any month, but only when the weekday is Monday. In short: 9:00 AM every Monday.
- How do I run a cron job every 5 minutes?
- Use the step syntax in the minute field:
*/5 * * * *. The*/5means every fifth minute (0, 5, 10, 15 …) and the asterisks mean every hour, day, month and weekday. - What does the asterisk (*) mean in cron?
- An asterisk means "every" valid value for that field. For example
*in the hour field matches every hour, so the field places no restriction on the schedule. - How do I schedule something monthly?
- Pick the day of month and time you want and leave month and day-of-week as asterisks. For example
0 0 1 * *runs at midnight on the first day of every month.