Cron expressions explained

Five fields decide when your job runs — and one subtle rule about days trips up almost everyone who edits a crontab for the first time. This is the mental model, the syntax, and the traps.

The five fields

FieldRangeExample
Minute0-590 — on the hour
Hour0-239 — 9 AM
Day of month1-311 — first of the month
Month1-12 (or JAN-DEC)*/3 — every quarter
Day of week0-6 (0=Sunday, 7 also Sunday)1-5 — weekdays

Both 0 and 7 mean Sunday — a compatibility leftover that has caused more than one duplicate-Sunday bug. Some systems (Quartz, some CI schedulers) add a sixth field for seconds, and Quartz uses ? where vixie cron uses *. Check which dialect your scheduler speaks before copying an expression from a tutorial.

Syntax building blocks

  • Lists: 0,15,30,45 runs at those exact minutes.
  • Ranges: 1-5 in the weekday field means Monday through Friday.
  • Steps: */10 in minutes means every 10th minute starting from the field's floor: 0, 10, 20, 30, 40, 50.
  • Named months/days: MON-FRI works on most modern crons.
  • Shortcuts: @hourly, @daily (midnight), @weekly, @monthly, and @reboot — the last one runs once at startup and is the standard way to launch daemons.

The trap: day-of-month and day-of-week are OR'ed

If both fields are restricted (neither is *), the job runs on either match — the union, not the intersection. So 0 0 1 * 1 does not mean "first Monday of the month". It means midnight on the 1st and midnight every Monday. That is specified POSIX behavior, and it is the single most common "why is this running twice?" question in cron.

Unfortunately, "first Monday of the month" has no clean vixie-cron syntax. Common workarounds: run a script that checks the date itself, or use a scheduler with richer syntax (Quartz, systemd timers, cloud schedulers). systemd timers are the modern replacement on most Linux servers and express this kind of logic properly.

Mistakes that fail silently

  • Wrong time zone. Cron runs in the system's local time — on a server set to UTC, 0 9 * * * fires at 17:00 Beijing time. Fix with CRON_TZ=Asia/Shanghai or by setting the system zone deliberately.
  • Missing environment. Cron's PATH is minimal (/usr/bin:/bin) and no shell profile loads. Scripts that work interactively and fail under cron almost always reference binaries or variables from your profile. Use absolute paths everywhere.
  • No output handling. Any output is emailed to the local mailbox — or nowhere if no MTA is installed. Redirect: job >> /var/log/job.log 2>&1.
  • Percent signs. The first unescaped % in the command starts a comment. Use \% when piping to a command like date +\%F.

Expressions worth memorizing

  • */5 * * * * — every 5 minutes
  • 0 2 * * * — daily at 02:00 (the classic backup slot)
  • 0 4 * * 1 — Mondays at 04:00 (weekly maintenance window)
  • 0 0 1 * * — midnight on the first of each month
  • 0 9-17 * * 1-5 — hourly during business hours, weekdays

Try it yourself

Paste any expression into the cron parser — it translates the fields into plain English and previews the next several run times, which is the fastest way to catch the day-field trap before it bites. And if the schedule involves dates, the timestamp converter helps you sanity-check what "midnight" means in the server's time zone.