Cron Expression Syntax: A Complete Reference Guide

Complete guide to cron syntax, with examples for common scheduling patterns.

syntaxbasicsscheduling

Cron Expression Syntax

Cron expressions define schedules for recurring tasks.

Standard Format (5 fields)

┌───────────── 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)
│ │ │ │ │

Special Characters

CharMeaningExample
Any value (every minute)
,List1,15,30 (at 1, 15, and 30)
-Range1-5 (1 through 5)
/Step/15 (every 15)

Common Patterns

# Every minute
    
# Every hour at minute 0
0

# Every day at midnight
0 0

# Every day at 2:30 AM
30 2
# Every Monday at 9:00 AM
0 9
1
# Every weekday at 9:00 AM
0 9
1-5
# First day of every month at midnight
0 0 1

# Every 15 minutes
/15
# Every 6 hours
0 /6

Special Strings

@yearly    # 0 0 1 1  (once a year)
@monthly # 0 0 1
(once a month)
@weekly # 0 0
0 (once a week)
@daily # 0 0
(once a day)
@hourly # 0 (once an hour)
@reboot # Run once at startup

Frequently Asked Questions

Common questions about this topic

*/5 means 'every 5 units starting from 0' (0, 5, 10...). 0/5 explicitly starts from 0 with the same result. But 2/5 would start from 2 (2, 7, 12...). For most cases, */5 is clearer and preferred. Some cron implementations don't support starting offsets.

Common issues: 1) Wrong timezone (cron uses system time, not UTC), 2) Path not set (use absolute paths), 3) Missing permissions, 4) Environment variables not loaded, 5) Syntax errors. Check cron logs: /var/log/cron or 'grep CRON /var/log/syslog'. Test your command manually first.

Not directly - cron can't express '45 minutes' cleanly. Options: 1) Two entries: '0 0,1,2... * * *' and '45 0,1,2... * * *', 2) Run every 15 minutes and check time in script, 3) Use a scheduler like systemd timers that support arbitrary intervals.