Cron Expressions Explained: Schedules, Special Strings & Pitfalls

Five small fields run half the internet's background jobs: backups at 2am, reports on Mondays, cache purges every five minutes. Learn to read and write cron β€” and dodge the day-of-month trap.

πŸ“‚ Developer Essentials ⏱ About 9 minutes πŸ“Ά Beginner πŸ› οΈ Pairs with: Cron Explainer

What you will learn

  • Read any five-field cron expression out loud
  • Use lists, ranges, steps and names correctly
  • Write the ten schedules everyone needs
  • Use @daily, @weekly and the other special strings
  • Avoid the day-of-month vs day-of-week trap, DST skips and timezone bugs
In this guide
  1. What cron is
  2. Anatomy: the five fields
  3. Special strings: the shortcuts
  4. The ten schedules everyone needs
  5. Timezone, DST and the environment
  6. Common mistakes
  7. Try it: Cron Explainer
  8. Frequently asked questions

What cron is

Cron is the time-based job scheduler built into Unix-like systems since the 1970s. You write a line in a crontab β€” a schedule plus a command β€” and the cron daemon runs that command whenever the schedule matches. Backups, log rotation, certificate renewal, report emails: most of the internet's boring, essential chores are cron lines someone wrote once and forgot about.

The idea is deliberately small: no programming, no queue, no retry logic β€” just β€œwhen the clock looks like this, run that”. That simplicity is why it survives, and why its quirks are worth learning rather than working around.

Anatomy: the five fields

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ minute (0–59)
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€ hour (0–23)
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€ day of month (1–31)
β”‚ β”‚ β”‚ β”Œβ”€β”€β”€ month (1–12)
β”‚ β”‚ β”‚ β”‚ β”Œβ”€ day of week (0–7, both 0 and 7 are Sunday)
β”‚ β”‚ β”‚ β”‚ β”‚
* * * * *  command to run
FieldValuesExamples
Minute0–590 = top of the hour
Hour0–232 = 2am
Day of month1–311 = the 1st
Month1–12 or JAN–DEC1 = January
Day of week0–7 or SUN–SAT1 = Monday

Each field accepts four notations: a single value (2), a list (1,15), a range (1-5), and a step (*/5 = every 5, 2-30/10 = 2, 12, 22). Names work too β€” MON-FRI reads better than 1-5 β€” but mixing names and numbers in one field is asking for trouble.

Special strings: the shortcuts

StringMeansEquivalent
@rebootOnce, at startupβ€”
@yearly / @annuallyOnce a year0 0 1 1 *
@monthlyOnce a month0 0 1 * *
@weeklyOnce a week0 0 * * 0
@daily / @midnightOnce a day0 0 * * *
@hourlyOnce an hour0 * * * *

These are supported by Vixie cron (the standard on Linux) and most cloud schedulers, but not by every implementation β€” check before relying on @reboot somewhere unusual.

The ten schedules everyone needs

0 2 * * *        every day at 2:00am (the classic backup slot)
*/5 * * * *      every 5 minutes
0 9 * * 1-5      weekdays at 9:00am
0 0 1 * *        the 1st of every month at midnight
0 0 * * 0        Sundays at midnight
30 4 1,15 * *   1st and 15th at 4:30am
0 8-18 * * *    every hour from 8am to 6pm
0 0 * * 6       Saturdays at midnight
15 3 * * *      every day at 3:15am
0 12 25 12 *    Christmas Day at noon

Why 2am for backups? It is the hour when the fewest people are using the system β€” and when a job overruns, the most hours remain before anyone notices. The tradition is older than most of the engineers who follow it.

Timezone, DST and the environment

Cron runs in the system's local time, not UTC, unless the daemon is configured otherwise β€” and on a server that may not be the timezone you think it is. A job scheduled for 2am that runs at 10am is usually a timezone mismatch, not a broken schedule. Always check date on the machine itself.

Daylight saving time adds two edge cases a year: in spring, 2:00–2:59am doesn't exist, so a 2:30am job simply doesn't run that day; in autumn it happens twice, so the job runs twice. Scheduling critical jobs at 2:30am is how you discover this the hard way β€” 3am is the safer slot.

Also remember cron runs with a minimal environment: your shell's PATH, variables and aliases are not there. Use absolute paths (/usr/bin/python3 /opt/backup.py), and redirect output to a log file β€” otherwise failures vanish silently. A cron job that fails quietly is worse than one that never ran.

Common mistakes

  • The day-of-month trap. In Vixie cron, when both day-of-month and day-of-week are restricted, the job runs when either matches (OR), not both. 0 0 1 * 1 runs on the 1st of the month and every Monday β€” not β€œMondays that are the 1st”. This is the single most misunderstood cron rule.
  • */5 vs 5. The first is every five minutes; the second is once an hour, at minute 5. A missing */ turns a frequent job into a rare one.
  • Forgetting the newline at the end of the crontab. Some cron versions silently ignore the last line if the file doesn't end with a newline.
  • % in the command. In a crontab, % means newline β€” it splits your command. Escape it as \% or move the logic into a script.
  • Assuming a seconds field. Classic cron has five fields, no seconds. Quartz and some cloud schedulers use six or seven (seconds first). Copying a six-field expression into a five-field crontab shifts every field and schedules something entirely different.
  • No logging. * * * * * /opt/job.sh >> /var/log/job.log 2>&1 β€” always.

Try it: Cron Explainer

Type any expression into the Cron Explainer and it tells you in plain English when it runs β€” plus the next ten run times. Try the tricky examples from this guide there first.

Open the Cron Explainer β†’

Keep learning

Frequently asked questions

How do I run something every 2 hours?

0 */2 * * * β€” minute 0, every second hour. For every 90 minutes there is no clean cron expression; run every 30 minutes and let the script check whether 90 minutes have passed, or use a systemd timer instead.

How do I run a job on weekdays only?

0 9 * * 1-5 β€” the day-of-week field 1-5 is Monday to Friday. Names work too: 0 9 * * MON-FRI. Remember 0 and 7 are both Sunday.

Does cron run if the computer is off?

No β€” cron only fires while the machine is running. A laptop that was asleep at 2am simply misses the job. For laptops use a tool that catches up on wake (anacron on Linux, launchd on macOS) or schedule around uptime.

How do I edit my crontab?

crontab -e opens your schedule in an editor; crontab -l lists it; crontab -r deletes it (careful β€” there is no undo). System-wide jobs live in /etc/crontab and /etc/cron.d/, with an extra user field in each line.

How can I test a cron expression without waiting?

Paste it into the Cron Explainer tool: it translates the expression into plain English and lists the next ten run times, so a wrong field shows up immediately instead of next Tuesday.