Understanding Cron Syntax in Unix & Linux
Originating in Unix operating systems and named after the Greek word Chronos (Time), Cron is a background job scheduler daemon used by DevOps engineers, SysAdmins, and cloud architects to automate recurring maintenance tasks. From running database backups and clearing cache to executing automated CI/CD batch jobs and sending digest emails, cron rules govern automated server workflows.
Despite its ubiquity, cron's terse whitespace-separated syntax is notoriously prone to human error. A single misplaced asterisk can cause a heavy batch job designed for monthly execution to execute every single minute, crippling server CPU and database connections.
The 5 Standard Cron Fields
| Field | Position | Allowed Values | Allowed Special Characters |
|---|---|---|---|
| Minute | 1st | 0 - 59 |
* , - / |
| Hour | 2nd | 0 - 23 (24-hour format) |
* , - / |
| Day of Month | 3rd | 1 - 31 |
* , - / ? L W |
| Month | 4th | 1 - 12 or JAN - DEC |
* , - / |
| Day of Week | 5th | 0 - 6 (0 = Sun) or SUN - SAT |
* , - / ? L # |
Common Production Cron Recipes
| Expression | Human Meaning | Common Engineering Use Case |
|---|---|---|
*/5 * * * * |
Every 5 minutes | Health checks, queue polling, worker heartbeats. |
0 * * * * |
Every hour on the hour | Hourly metrics aggregation, cache warmers. |
0 0 * * * |
Daily at midnight (00:00) | Daily log rotation, database vacuum / optimize. |
0 9 * * 1-5 |
Mon through Fri at 09:00 AM | Business weekday morning summary reports. |
0 2 1 * * |
1st of every month at 02:00 AM | Monthly billing cycle settlement, archive backups. |