⏱️
← Back to Guides

Cron Expression Syntax: A Complete Guide with Examples

· Tags: cron-syntax, crontab-format, cron-fields, cron-expression-guide, linux-automation

Cron Expression Syntax

Cron is the standard job scheduler on Unix-like systems. Every cron expression defines a schedule in a compact string that specifies when a command should run. Understanding the syntax is essential for automating backups, log rotation, and maintenance tasks.

The 5-Field Format

A standard cron expression has five fields separated by spaces:

* * * * *
| | | | |
| | | | +----- Day of the Week (0-7, 0 and 7 = Sunday)
| | | +------- Month (1-12)
| | +--------- Day of the Month (1-31)
| +----------- Hour (0-23)
+------------- Minute (0-59)

Field Details

| Field | Range | Special Characters | Example | |-------|-------|-------------------|---------| | Minute | 0-59 | , - * / | 30 = at minute 30 | | Hour | 0-23 | , - * / | 6 = at 6 AM | | Day of Month | 1-31 | , - * / | 15 = on the 15th | | Month | 1-12 | , - * / | 6 = in June | | Day of Week | 0-7 | , - * / | 0 = on Sunday |

Minute controls the exact minute of execution: 30 * * * * runs at minute 30 of every hour. Hour defines the time of day: 0 6 * * * runs at 6:00 AM daily. Day of month restricts to specific calendar dates: 0 0 15 * * runs on the 15th of every month at midnight. Month limits execution to specific months: 0 0 1 6 * runs on June 1st. Day of week controls which weekdays: 0 8 * * 1-5 runs at 8 AM Monday through Friday.

Important: Days 29-31 only execute in months that have those dates. In shorter months, those values are silently skipped.

Special Characters

| Char | Name | Purpose | Example | |------|------|---------|---------| | * | Asterisk | All possible values | * in minute = every minute | | , | Comma | List values | 1,15,30 = minutes 1, 15, 30 | | - | Hyphen | Range | 9-17 = hours 9 through 17 | | / | Slash | Step values | */5 = every 5 minutes |

Step Values with Slash

The slash expresses "every N units":

# Every 5 minutes
*/5 * * * *

# Every 2 hours
0 */2 * * *

# Every 15 minutes during business hours
*/15 9-17 * * *

Common Cron Schedule Patterns

| Schedule | Expression | Description | |----------|------------|-------------| | Every minute | * * * * * | Runs 1,440 times per day | | Every 5 minutes | */5 * * * * | Health checks, monitoring | | Every hour | 0 * * * * | Top of each hour | | Twice daily | 0 6,18 * * * | 6 AM and 6 PM | | Daily at midnight | 0 0 * * * | Classic maintenance | | Weekly Sunday | 0 0 * * 0 | Weekly maintenance | | 1st of month | 0 0 1 * * | Monthly reports | | Weekdays 9 AM | 0 9 * * 1-5 | Business hours start |

Non-Standard Shortcuts

Some cron implementations support named shortcuts: @yearly (Jan 1), @monthly (1st of month), @weekly (Sunday), @daily (midnight), @hourly, and @reboot (runs once at system start). Supported by Vixie cron, cronie, and systemd timers.

Common Mistakes

  • Setting both day-of-month and day-of-week creates an OR condition — the job runs when either matches, which is rarely the intent.
  • Cron uses the system timezone. Jobs near daylight saving transitions may run twice or not at all.
  • Always count five fields. Four fields is invalid; six fields requires extended cron syntax.

Test Your Cron Expressions

Use the cron expression validator to check syntax, preview upcoming execution times, and catch errors before they affect production. A thirty-second validation check prevents silent scheduling failures.