Cron Expressions Demystified: A Beginner's Guide

Cron is the time-based job scheduler built into every Unix-like system. Whether you're scheduling database backups, clearing cache, or sending email digests, cron is the tool for the job. The only catch: its syntax looks like line noise until you know how to read it.

This guide will take you from zero to confidently writing cron expressions.

The Five Fields

A standard 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, Sunday=0)
│ │ │ │ │
* * * * *

Each field defines when the job should run. The job fires when all five fields match the current time.

Special Characters

CharacterMeaningExample
*Any value* * * * * — every minute
,List of values0,30 * * * * — at :00 and :30
-Range0 9-17 * * * — every hour, 9am–5pm
/Step interval*/5 * * * * — every 5 minutes

These characters can be combined. For example, 1-30/5 in the minute field means "every 5 minutes during the first half-hour" (minutes 1, 6, 11, 16, 21, 26).

Reading Cron Expressions

The trick is to read each field left to right. Let's decode a few:

30 2 * * *

"At minute 30 of hour 2, every day of the month, every month, every day of the week" — or simply: every day at 2:30 AM.

0 */6 * * *

"At minute 0, every 6th hour" — every 6 hours (midnight, 6am, noon, 6pm).

0 9 * * 1-5

"At 9:00 AM, only on days of the week 1 through 5" — weekdays at 9am.

0 0 1 * *

"At midnight on the 1st day of every month" — monthly at midnight.

Common Schedules

Here are the cron expressions developers reach for most often:

ExpressionSchedule
* * * * *Every minute
*/5 * * * *Every 5 minutes
*/15 * * * *Every 15 minutes
0 * * * *Every hour (on the hour)
0 0 * * *Daily at midnight
0 9 * * 1-5Weekdays at 9am
0 0 * * 0Weekly (Sunday midnight)
0 0 1 * *Monthly (1st at midnight)
0 0 1 1 *Yearly (January 1st at midnight)

Tip: Some systems support shorthand aliases: @hourly, @daily, @weekly, @monthly, and @yearly. These are equivalent to the expressions above, but not every cron implementation supports them.

Real-World Examples

Database Backup Every Night

# Run pg_dump at 3:30 AM daily
30 3 * * * /usr/local/bin/pg_dump mydb > /backups/mydb_$(date +\%Y\%m\%d).sql

Clear Temp Files Weekly

# Every Sunday at 4 AM
0 4 * * 0 find /tmp -type f -mtime +7 -delete

Health Check Every 5 Minutes During Business Hours

# Mon-Fri, 8am-6pm, every 5 min
*/5 8-18 * * 1-5 curl -s https://api.example.com/health >> /var/log/health.log

Monthly Report on the 1st

# 1st of each month at 7 AM
0 7 1 * * /opt/scripts/generate-report.sh | mail -s "Monthly Report" team@example.com

Common Pitfalls

Watch out for day-of-month + day-of-week conflicts. If you set both fields (not *), the job runs when either matches — not both. 0 0 15 * 5 runs on the 15th of every month and every Friday, not "the 15th if it's a Friday."

Editing Crontabs

Use crontab -e to edit your user's crontab, and crontab -l to list it:

# List current cron jobs
crontab -l

# Edit crontab (opens in $EDITOR)
crontab -e

# Edit another user's crontab (requires root)
sudo crontab -u www-data -e

Tip: Always test a new cron job with a short interval first (e.g., every minute), verify it works, then change it to the real schedule. Saves hours of debugging.

Build Cron Expressions Visually

BoltKit's CronBuilder tool lets you build cron expressions with visual field editors, quick presets, and a preview of the next scheduled runs — so you never get the syntax wrong.

Get BoltKit Free