Cron Expression Syntax for Beginners
Cron is the standard job scheduler on Unix and Linux systems. It runs commands on a schedule defined by a five-field expression. Whether you are scheduling database backups, log rotation, CI/CD pipelines, or Kubernetes CronJobs, understanding cron syntax is an essential skill.
This guide teaches the five-field format from scratch with practical examples you can use today.
The Five Fields
A cron expression has five fields separated by spaces:
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sun=0)
│ │ │ │ │
* * * * *
Each field accepts:
- A specific value:
5 - A wildcard (any value):
* - A range:
1-5 - A list:
1,3,5 - A step:
*/15(every 15th value)
Common Examples
| Expression | Schedule |
|---|---|
* * * * * | Every minute |
0 * * * * | Every hour (at minute 0) |
0 0 * * * | Daily at midnight |
0 9 * * 1-5 | Weekdays at 9:00 AM |
0 0 1 * * | First of every month at midnight |
*/15 * * * * | Every 15 minutes |
0 */6 * * * | Every 6 hours |
30 2 * * 0 | Sundays at 2:30 AM |
0 9,17 * * * | At 9:00 AM and 5:00 PM daily |
0 0 * * 1 | Every Monday at midnight |
Field Details
Minute (0-59)
0 → at the top of the hour
30 → at half past
*/5 → every 5 minutes (0, 5, 10, 15, ...)
5,35 → at minutes 5 and 35
Hour (0-23)
Uses 24-hour format. 0 is midnight, 12 is noon, 23 is 11 PM.
9 → 9:00 AM
*/2 → every 2 hours (0, 2, 4, 6, ...)
9-17 → every hour from 9 AM to 5 PM
Day of Month (1-31)
1 → first of the month
15 → fifteenth
1,15 → first and fifteenth
Not all months have 31 days. If you schedule day 31, the job skips months with fewer days.
Month (1-12)
1 → January
6 → June
1-3 → January through March
*/3 → every 3 months (Jan, Apr, Jul, Oct)
Day of Week (0-6)
0 and 7 both mean Sunday. 1 = Monday through 6 = Saturday.
0 → Sunday
1-5 → Monday through Friday (weekdays)
6,0 → weekends
Step Syntax (*/n)
The step syntax */n means "every nth value starting from the field minimum":
*/15in the minute field → 0, 15, 30, 45*/6in the hour field → 0, 6, 12, 18*/2in the day-of-week field → 0, 2, 4, 6
You can combine steps with ranges: 1-30/5 means every 5th value from 1 to 30 (1, 6, 11, 16, 21, 26).
Real-World Examples
Database backup every night at 2 AM
0 2 * * *
Log rotation every Sunday at 3:30 AM
30 3 * * 0
Health check every 5 minutes during business hours
*/5 9-17 * * 1-5
Monthly report on the 1st at 8 AM
0 8 1 * *
Deploy to staging every weekday at 6 PM
0 18 * * 1-5
Common Mistakes
- Confusing day-of-month and day-of-week — if both are set to non-wildcard values, most cron implementations run when either matches (OR logic), not when both match (AND logic). This catches many people.
- Timezone confusion — system cron uses the server's timezone. Kubernetes CronJobs default to UTC. Always specify which timezone your schedule targets.
- Running at boot, not by schedule —
@rebootis a special string, not a cron expression. It runs once when the cron daemon starts. - Forgetting that
*/nstarts at 0 —*/10in the hour field runs at 0:00, 10:00, 20:00 — not at the current time plus 10 hours. - Output accumulation — cron emails stdout and stderr to the user. Redirect output to avoid filling the mailbox:
0 * * * * /path/to/script > /dev/null 2>&1
Special Strings
Most cron implementations support these shortcuts:
| String | Equivalent |
|---|---|
@yearly | 0 0 1 1 * |
@monthly | 0 0 1 * * |
@weekly | 0 0 * * 0 |
@daily | 0 0 * * * |
@hourly | 0 * * * * |
@reboot | Run once at startup |
Try It
Build and validate cron expressions interactively with StackCache Cron Schedule Builder. It shows the next execution times and translates expressions into plain English — all in your browser with no account needed.
Try it yourself
Open the tool mentioned in this guide — it runs locally in your browser, no account needed.
Open tool