A cron expression is five short fields that tell a scheduler when to run a job. Once you know the fields and the four operators, you can read almost any crontab line in seconds. The rule that catches experienced people out is how cron combines the two day fields, so this guide covers that too.
Step by step
- Open the cron expression explainer and type or paste an expression such as
30 9 * * 1-5, or click one of the examples. - Read the plain-English meaning, here "At 09:30, Monday through Friday", and the breakdown of each field.
- Check the list of the next 10 run times. They are shown in your browser's time zone.
- If your server runs in UTC, tick Also show UTC to see both side by side. This is the quickest way to catch a job that runs an hour or a day off from what you intended.
- If the expression is invalid, the error names the field that is wrong, for example "Field 2 (hour): 24 is out of range 0–23."
The five fields
A standard cron line has five fields separated by spaces, followed by the command in a crontab:
┌───────── minute (0–59)
│ ┌─────── hour (0–23)
│ │ ┌───── day of month (1–31)
│ │ │ ┌─── month (1–12 or JAN–DEC)
│ │ │ │ ┌─ day of week (0–7 or SUN–SAT, 0 and 7 are Sunday)
│ │ │ │ │
30 9 * * 1-5 /usr/local/bin/report.sh
Hours use the 24-hour clock, so 2 p.m. is 14. Names are case-insensitive three-letter abbreviations.
Some schedulers add a sixth field for seconds or a seventh for years, and Quartz (used by many Java applications) adds the special characters ?, L, W and #. Those are different dialects. The explainer supports the standard five-field format used by Vixie cron, cronie, most Linux distributions and many hosted schedulers, and it tells you when an expression looks like Quartz syntax instead of misreading it.
The four operators
Each field can contain a single value or a combination of these:
| Operator | Example | Meaning |
|---|---|---|
* |
* in hour |
Every value: every hour |
, list |
0,30 in minute |
Each listed value: minutes 0 and 30 |
- range |
1-5 in day of week |
Every value from 1 to 5: Monday to Friday |
/ step |
*/15 in minute |
Every 15th value: 0, 15, 30, 45 |
Steps can also apply to a range. 0-30/10 in the minute field means 0, 10, 20 and 30. A step on a single number, such as 5/10, is treated by Vixie cron as "from 5 to the end of the range in steps of 10", so it means 5, 15, 25, 35, 45 and 55.
Note that a step counts from the start of the field's range, not from the current time. */7 in the minute field runs at 0, 7, 14 … 56 and then again at 0, so the gap across the top of the hour is only four minutes. Steps divide evenly only when the step is a factor of the range, such as 5, 10, 15, 20 or 30 for minutes.
The day-of-month and day-of-week rule
This is the part of cron most often misread. When both the day-of-month and the day-of-week fields are restricted (neither starts with *), cron runs the job on days that match either field, not both.
0 0 13 * 5
This does not mean "Friday the 13th". It means "at midnight on the 13th of every month, and also every Friday". The explainer reads it as "At 00:00, on day 13 of the month or on Friday".
If either field starts with *, the other one alone decides. So 0 0 * * 5 is every Friday, and 0 0 13 * * is the 13th of every month.
There is no way to express "the first Monday of the month" in standard cron. 0 9 1-7 * 1 looks right, but because both day fields are restricted it runs on days 1 to 7 and on every Monday. The usual workaround is to schedule on days 1 to 7 and check the weekday in the command:
0 9 1-7 * * [ "$(date +\%u)" = 1 ] && /usr/local/bin/monthly-report.sh
The % sign is escaped as \% because in a crontab an unescaped % ends the command and starts its standard input.
Common schedules
| Expression | Meaning |
|---|---|
* * * * * |
Every minute |
*/5 * * * * |
Every 5 minutes |
0 * * * * |
At the start of every hour |
0 */6 * * * |
At 00:00, 06:00, 12:00 and 18:00 |
0 0 * * * |
Every day at midnight |
30 9 * * 1-5 |
09:30 on weekdays |
0 9-17 * * 1-5 |
On the hour from 09:00 to 17:00 on weekdays |
0 3 * * SUN |
03:00 every Sunday |
0 2 1 * * |
02:00 on the first day of each month |
0 0 1 1 * |
Midnight on 1 January |
Many cron implementations also accept macros: @hourly, @daily (or @midnight), @weekly, @monthly and @yearly (or @annually). They are shorthand for 0 * * * *, 0 0 * * *, 0 0 * * 0, 0 0 1 * * and 0 0 1 1 *. The explainer expands them for you. @reboot also exists, but it runs once at startup and has no schedule to explain.
Time zones and daylight saving
Cron evaluates the schedule against the clock of the machine or service that runs it. On many servers and in most container images that is UTC, so 0 9 * * * runs at 09:00 UTC, which may be early morning or late afternoon for you. Check before assuming.
On servers that use local time, daylight saving skips an hour in spring and repeats one in autumn, and cron daemons handle this differently. Avoid scheduling important jobs between 01:00 and 03:00 local time, or run the scheduler in UTC. To work out what a given UTC run time means elsewhere, the time zone converter helps, and the Unix timestamp converter translates the epoch times that appear in job logs. If you are setting a job around a meeting in another country, see how to convert time zones for a meeting.
Tip Before deploying a new schedule, paste it into the explainer and compare the next 10 run times with what you expect. Mistakes such as swapping the minute and hour fields (
9 30 * * *is invalid, because 30 is not an hour) are caught immediately.