elefcode
← All guides

Dev Basics · 5 min read

Understanding Cron Syntax (With Examples)

Cron is the classic way to run tasks on a schedule on Unix systems, and its syntax powers everything from backups to newsletter sends. The five-field format looks cryptic at first but is simple once you see the pattern.

This guide walks through each field, the special characters, and practical examples you can adapt.

Try it yourself with the related tool.

Build a cron expression

Advertisement

The five fields

A standard cron expression has five fields, in order: minute (0–59), hour (0–23), day of month (1–31), month (1–12), and day of week (0–6, where 0 is Sunday). A job runs when the current time matches all the fields.

For example, 30 9 * * 1 means "at 9:30, on any day of the month, in any month, but only on Monday."

The special characters

An asterisk * means "every" value for that field. A slash defines steps: */15 in the minute field means every 15 minutes. Commas list values: 0,30 means at :00 and :30. A hyphen sets a range: 9-17 means from 9 through 17.

Common schedules

Every 15 minutes: */15 * * * *. Every day at midnight: 0 0 * * *. Every weekday at 8am: 0 8 * * 1-5. On the first of every month: 0 0 1 * *. Every Sunday at 3am: 0 3 * * 0.

Watch out for timezones

Cron runs in the server's local timezone unless configured otherwise. A job scheduled for "midnight" runs at midnight wherever the server thinks it is — a frequent source of surprise. Always confirm the timezone your scheduler uses.

Related guides