env.dev

Cron Expression Syntax: A Complete Guide

Cron expression syntax explained: 5- and 6-field formats, special characters (* , - / L W #), common schedules, and platform-specific differences.

Last updated:

A cron expression is a string of 5 (or 6) fields that defines a recurring schedule for running automated tasks. It is the standard format used in Unix cron jobs, CI/CD pipelines, cloud schedulers (AWS EventBridge, GitHub Actions), and most backend job frameworks.

What does each field in a cron expression mean?

text
┌─────────── minute        (0–59)
│ ┌───────── hour          (0–23)
│ │ ┌─────── day of month  (1–31)
│ │ │ ┌───── month         (1–12 or JAN–DEC)
│ │ │ │ ┌─── day of week   (0–6 or SUN–SAT, 0=Sunday)
│ │ │ │ │
* * * * *

Some systems add a 6th field for seconds (Quartz, Spring) at the beginning, or a 6th year field at the end.

What do the special characters (* , - / L W #) do?

CharacterNameMeaning
*WildcardEvery value in the field
,ListMultiple values: 1,3,5
-RangeA range of values: 1-5
/StepEvery N values: */5 = every 5 minutes
LLastLast day of month or week (some implementations)
WWeekdayNearest weekday to given day (some implementations)
#Nth3rd Monday = MON#3 (some implementations)

What are common cron schedule examples?

* * * * *Every minute
*/5 * * * *Every 5 minutes
0 * * * *Every hour (at :00)
0 */2 * * *Every 2 hours
0 9 * * *Daily at 9:00 AM
0 0 * * *Daily at midnight
0 9 * * MON-FRIWeekdays at 9:00 AM
0 9 * * 1Every Monday at 9:00 AM
0 0 1 * *First day of every month at midnight
0 0 1 1 *Once a year on January 1st at midnight
30 8 * * 1-5Weekdays at 8:30 AM
0 0,12 * * *Twice daily: midnight and noon
0/30 * * * *Every 30 minutes (Quartz syntax)

Can I use month and day-of-week names instead of numbers?

Months

NumberName
1JAN
2FEB
3MAR
4APR
5MAY
6JUN
7JUL
8AUG
9SEP
10OCT
11NOV
12DEC

Days of Week

NumberName
0 (or 7)SUN
1MON
2TUE
3WED
4THU
5FRI
6SAT

How do cron implementations differ across platforms?

Watch out: AWS EventBridge and Quartz use a 6-field syntax with seconds as the first field (Quartz) or with a year field at the end (EventBridge, valid range 1970–2199). GitHub Actions uses standard 5-field cron but always runs in UTC. Some systems treat 0 and 7 as Sunday for day-of-week. Always check your platform's documentation.

How do timezones affect cron schedules?

The schedule 0 9 * * * means "9 AM" — but in which timezone? The answer depends on where the cron daemon runs, not where you wrote the expression. A schedule that fires at 9 AM in your local editor can land at 1 AM in production if the host is set to UTC.

  • System cron (Linux): reads the TZ environment variable, otherwise uses /etc/localtime. Inside Docker, the default is UTC unless the image setsTZ or mounts /etc/localtime.
  • vixie/cronie: supports a CRON_TZ=Europe/Stockholm line at the top of a crontab to pin the schedule to a named zone.
  • GitHub Actions: always UTC. 0 9 * * * fires at 09:00 UTC, which is 04:00 in New York during EST. There is no per-workflow timezone option.
  • AWS EventBridge: historic Rules use UTC only. EventBridge Scheduler (released 2022) accepts a ScheduleExpressionTimezone parameter, including DST-aware zones like America/New_York.
  • Daylight Saving Time: a job scheduled for 02:30 local can run twice on fall-back day or skip on spring-forward day. UTC sidesteps both.

For workflow-specific tips, see the GitHub Actions cheatsheet.

How do I debug a cron job that doesn't run?

Most failed cron jobs aren't broken cron expressions — they're environment, path, or permission problems. Walk through these checks in order:

  1. Confirm the entry is installed: run crontab -l as the user that owns the job. System-wide entries live in /etc/crontab and /etc/cron.d/*.
  2. Check cron logs: on Debian/Ubuntu look at /var/log/syslog filtered with grep CRON; on RHEL/CentOS check /var/log/cron; under systemd use journalctl -u cron or journalctl -u crond.
  3. Cron has a minimal PATH: usually only /usr/bin:/bin. Use absolute paths in commands or set PATH=... at the top of the crontab.
  4. Capture stderr: append >> /var/log/myjob.log 2>&1 to the command, or set MAILTO=ops@example.com at the top of the crontab to receive failures by email.
  5. End the line with a newline: entries without a trailing newline are silently ignored on some implementations.
  6. Validate the expression: paste it into the Cron Expression Parser to see the next 5 fire times. If they don't match what you expected, the bug is in the expression.
  7. Container caveats: Docker images often ship without a cron daemon, run with PID 1 not forking, and default to UTC. Use a sidecar scheduler or your platform's native scheduler (EventBridge, Cloud Scheduler, Kubernetes CronJob) instead of stuffing cron inside an app container.

References

Parse and explain any cron expression with the Cron Expression Parser tool, or grab copy-paste schedules from the Cron examples cheatsheet.

Was this helpful?

Read next

GitHub Actions: Secrets vs Environment Variables

When to use repository secrets, environment secrets, and configuration variables in GitHub Actions. Includes workflow examples for Node.js, Python, and Docker.

Continue →

Frequently Asked Questions

What does * mean in a cron expression?

The asterisk (*) means "every possible value" for that field. For example, * in the hour field means "every hour", and * in the day-of-week field means "every day of the week".

How do I run a cron job every 5 minutes?

Use the expression */5 * * * *. The */5 in the minute field means "every 5th minute". The asterisks in the remaining fields mean every hour, every day, every month, every weekday.

What is the cron expression for daily at midnight?

Use 0 0 * * * to run at midnight (00:00) every day. The first 0 is the minute field and the second 0 is the hour field.

What is the difference between cron and crontab?

cron is the daemon (background service) that executes scheduled tasks. crontab is the command and file format used to create, edit, and manage the schedule entries that cron reads.

Stay up to date

Get notified about new guides, tools, and cheatsheets.