DevOps & Automation
Understanding Cron Syntax: Standard 5-Field vs 6-Field Expressions
Cron jobs are the backbone of automated task scheduling in Linux, Kubernetes, AWS EventBridge, and backend services. Yet, crontab syntax remains one of the most frequently misconfigured patterns in software engineering.
The Standard UNIX 5-Field Cron Format
Standard Linux cron daemon expressions contain exactly five fields separated by whitespace:
┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of the month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
│ │ │ │ │
* * * * *
The Extended 6-Field Format (Seconds or Years)
Modern frameworks like Spring, Quartz, and NestJS often support or require a 6-field expression. Usually, the first field represents seconds:
┌───────────── second (0 - 59)
│ ┌───────────── minute (0 - 59)
│ │ ┌───────────── hour (0 - 23)
│ │ │ ┌───────────── day of month (1 - 31)
│ │ │ │ ┌───────────── month (1 - 12)
│ │ │ │ │ ┌───────────── day of week (0 - 7)
│ │ │ │ │ │
* * * * * *
Special Characters Demystified
*(Asterisk): Matches every value in the field (e.g. every minute).,(Comma): Delimits list items (e.g.1,15,30).-(Hyphen): Specifies inclusive ranges (e.g.9-17for 9 AM to 5 PM)./(Slash): Specifies step intervals (e.g.*/15for every 15 minutes).?(Question Mark): Used in Quartz / AWS to mean "no specific value" when specifying day-of-month or day-of-week.