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.

FieldRangeNotes
Minute0–59No sub-minute scheduling in standard cron.
Hour0–2324-hour clock; 0 is midnight.
Day of month1–31Values above the month length never match.
Month1–12Names like JAN are accepted by many daemons.
Day of week0–6 (7 = Sunday)0 Sunday, 1 Monday … 6 Saturday.

Operators

OperatorMeaningExample
*Every value in the field* * * * * runs every minute
/Step within a range*/15 runs at minutes 0, 15, 30, 45
-Inclusive range1-5 in weekday means Mon–Fri
,List of values1,15 in day-of-month means the 1st and 15th
?No specific value (Quartz only)0 0 9 ? * MON-FRI
LLast (Quartz only)L in day-of-month = last day
WNearest 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.

MacroEquivalentMeaning
@yearly / @annually0 0 1 1 *Once a year, January 1 at midnight
@monthly0 0 1 * *First day of every month
@weekly0 0 * * 0Every Sunday at midnight
@daily / @midnight0 0 * * *Every day at midnight
@hourly0 * * * *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 meant 0 * * * * — every minute instead of every hour.
  • */5 when you meant 5 — every five minutes instead of minute 5.
  • 0 0 1 * 1 when 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, W or # in a Unix crontab — those are Quartz-only characters.