Mastering Cron Expressions: Syntax, Special Operators, and Scheduling Best Practices
Demystify crontab syntax. Learn the 5-field structure, special characters like asterisk, slash, comma, and hyphen, edge cases with day-of-week, and scheduling in Kubernetes and Linux.
Cron Job Generator & Human Translator
Build valid cron schedules visually and translate raw expressions into plain human English.
What is Cron?
Derived from the Greek word Chronos (meaning time), Cron is a background time-based job scheduler native to Unix-like operating systems. Since its creation in Version 7 Unix in 1979, Cron has remained the universal industry standard for running recurring tasks, database backups, cache invalidations, and system health checks.
In modern distributed systems, the same cron expression format is adopted by:
schedule: - cron: '0 0 *').Standard 5-Field Crontab Structure
A traditional Unix cron expression consists of five fields separated by spaces:
┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of month (1 - 31)
│ │ │ ┌───────────── month (1 - 12 or JAN - DEC)
│ │ │ │ ┌───────────── day of week (0 - 6, Sunday = 0 or 7)
│ │ │ │ │
*
| Field | Description | Allowed Values | Special Characters |
|---|---|---|---|
| Minute | Minute of the hour | 0 - 59 | * , - / |
| Hour | Hour of the day (24-hr clock) | 0 - 23 | * , - / |
| Day of Month | Day of the calendar month | 1 - 31 | * , - / L W |
| Month | Month of the year | 1 - 12 or JAN - DEC | * , - / |
| Day of Week | Day of the week | 0 - 6 (0 = Sun) or SUN - SAT | * , - / # L |
Special Operators Explained
1. The Asterisk (): Wildcard representing "every possible value" for that field. fires every single minute of every day.
2. The Comma (,): Value separator specifying an explicit list of triggers. 0,15,30,45 triggers at minute 0, 15, 30, and 45.
3. The Hyphen (-): Range operator defining an inclusive interval. 0 9-17 1-5 runs at minute 0 of every hour from 9 AM to 5 PM, Monday through Friday.
4. The Slash (/): Step operator specifying recurring increments. /10 triggers every 10 minutes (0, 10, 20, 30, 40, 50). 5/15 * means "starting at minute 5, every 15 minutes" (5, 20, 35, 50).
8 Essential Real-World Cron Recipes
| Schedule Requirement | Cron Expression | Explanation |
|---|---|---|
| Every 15 Minutes | /15 * | Runs at minute 0, 15, 30, and 45 of every hour |
| Every Hour on the Hour | 0 | Runs at XX:00 every single hour |
| Every Night at Midnight | 0 0 * | Perfect for nightly log rotation & partition creation |
| Weekdays at 9:00 AM | 0 9 1-5 | Monday through Friday morning batch report processing |
| Twice Daily (6 AM & 6 PM) | 0 6,18 * | Database replication sync twice per day |
| Every Sunday at 2:30 AM | 30 2 0 | Low-traffic maintenance and vacuum tasks |
| First Day of Every Month | 0 0 1 | Monthly billing generation and invoicing |
| Every Quarter (Q1-Q4) | 0 0 1 1,4,7,10 * | Quarterly financial aggregation runs |
The Common Day-of-Month vs Day-of-Week Gotcha
One of the most frequent misconceptions in crontab scheduling occurs when both Day of Month and Day of Week are specified.
In standard POSIX cron, if both fields are non-wildcard, they operate with logical OR, not logical AND! For example:
0 0 13 * 5
This does NOT mean "every Friday the 13th". It means:
> "Run at midnight if it is the 13th day of the month OR if it is a Friday."
To truly execute a script only on Friday the 13th, trigger the job every Friday and verify the date inside your shell script:
0 0 5 [ $(date +%d) -eq 13 ] && /opt/scripts/friday13th.sh
Production Best Practices
0 2 * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
flock to enforce single execution:/15 * /usr/bin/flock -n /tmp/backup.lock /opt/scripts/backup.sh
Struggling to remember exact syntax? Use our visual Cron Job Generator to toggle schedules with zero syntax errors.
Editorial Integrity & Peer Review
All technical guides on MicroTools are independently authored and peer-reviewed by software and infrastructure professionals. Content is updated periodically to ensure compliance with the latest IETF RFC specifications, IEEE standards, and cloud provider architectural recommendations.