The five fields
A complete crontab line is the five fields, optional whitespace, and the command. System crontabs (/etc/crontab, /etc/cron.d/*) insert a user field between the schedule and the command; user crontabs do not. That difference is the most common reason a copied line is rejected.
| Field | Range | Notes |
|---|---|---|
| Minute | 0–59 | No sub-minute scheduling in standard cron. |
| Hour | 0–23 | 24-hour clock; 0 is midnight. |
| Day of month | 1–31 | Values above the month length never match. |
| Month | 1–12 | Names like JAN are accepted by many daemons. |
| Day of week | 0–6 (7 = Sunday) | 0 Sunday, 1 Monday … 6 Saturday. |
Operators
| Operator | Meaning | Example |
|---|---|---|
* | Every value in the field | * * * * * runs every minute |
/ | Step within a range | */15 runs at minutes 0, 15, 30, 45 |
- | Inclusive range | 1-5 in weekday means Mon–Fri |
, | List of values | 1,15 in day-of-month means the 1st and 15th |
? | No specific value (Quartz only) | 0 0 9 ? * MON-FRI |
L | Last (Quartz only) | L in day-of-month = last day |
W | Nearest weekday (Quartz only) | 15W = weekday closest to the 15th |
# | Nth weekday (Quartz only) | MON#2 = second Monday |
Steps can be combined with ranges: 0-30/10 means minutes 0, 10, 20 and 30. A bare 5/10 starts at 5 and repeats every 10, which is not the same as */10.
Macros
Many implementations accept shorthand macros. They are convenient, but they are not portable to every minimal cron build, so expand them if the job must survive a base-image change.
| Macro | Equivalent | Meaning |
|---|---|---|
| @yearly / @annually | 0 0 1 1 * | Once a year, January 1 at midnight |
| @monthly | 0 0 1 * * | First day of every month |
| @weekly | 0 0 * * 0 | Every Sunday at midnight |
| @daily / @midnight | 0 0 * * * | Every day at midnight |
| @hourly | 0 * * * * | Every hour at minute 0 |
| @reboot | — | Once when the daemon starts (not portable) |
Reading an expression from left to right
Take */10 9-17 * * 1-5. The minute field says every ten minutes; the hour field says only between 09:00 and 17:59; day-of-month and month are unrestricted; weekday says Monday through Friday. The combined schedule is 9:00, 9:10, 9:20 … 17:50 on weekdays — 54 runs per day, not “every ten minutes, all day”.
Now compare 0 0 1 * 1. Both day fields are restricted, so Vixie cron uses OR: midnight on the 1st of the month and every Monday at midnight. If you wanted only the first Monday, Unix cron cannot express it; Quartz's 1#1 can.
Mistakes that pass validation but do the wrong thing
* * * * *when you meant0 * * * *— every minute instead of every hour.*/5when you meant5— every five minutes instead of minute 5.0 0 1 * 1when you meant monthly — OR semantics make it weekly too.0 0 0 1 1 *pasted into Unix cron — that is Quartz's six-field layout, not Unix.0 2 30 2 *when you meant February 30th — the date does not exist; it never runs.- Using
L,Wor#in a Unix crontab — those are Quartz-only characters.