Cron field syntax: stars, steps, ranges and lists
A field by field guide to writing cron expressions, covering the wildcard, step, range and list operators and the day of week gotcha.
The five fields and their ranges
A standard cron line has five whitespace-separated fields that answer minute, hour, day of month, month and day of week, in that fixed order. Their valid ranges are 0-59, 0-23, 1-31, 1-12 and 0-6. A sixth item on the line is not part of the schedule; it is the command cron runs when the time matches. Getting the order right is the most common fix when a job never fires, since swapping hour and day of month silently produces a legal but wrong schedule.
The four operators you can combine
Each field accepts four building blocks. A lone asterisk matches every value. A step written as */n runs every nth unit, so */15 in the minute field fires at 0, 15, 30 and 45. A range like 9-17 covers every value from 9 to 17 inclusive. A comma list such as 1,15,30 picks out specific values. You can nest a step inside a range, for example 0-30/10, and this generator validates each part against the field's range before it lets you copy the line.
The day-of-month and day-of-week trap
When both the day of month and the day of week are set to something other than *, most cron daemons treat them as an OR rather than an AND. A line like '0 0 13 * 5' does not mean the 13th only when it is a Friday; it means every 13th and every Friday. To target a weekday of the month reliably you usually set one field and add a test in the command itself. Keeping one of the two fields at * avoids the surprise entirely.
From expression to running job
Once the expression is correct, open your crontab with crontab -e, which loads it in your default editor. Each active line is a schedule followed by a command, for example '0 3 * * * /usr/bin/backup.sh'. Cron uses the system's local time zone unless your daemon is configured otherwise, so double-check the zone on servers. Save the file, and cron reloads it automatically; there is no separate restart step.