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.
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
- What cron is
- Anatomy: the five fields
- Special strings: the shortcuts
- The ten schedules everyone needs
- Timezone, DST and the environment
- Common mistakes
- Try it: Cron Explainer
- 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
| Field | Values | Examples |
|---|---|---|
| Minute | 0β59 | 0 = top of the hour |
| Hour | 0β23 | 2 = 2am |
| Day of month | 1β31 | 1 = the 1st |
| Month | 1β12 or JANβDEC | 1 = January |
| Day of week | 0β7 or SUNβSAT | 1 = 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
| String | Means | Equivalent |
|---|---|---|
@reboot | Once, at startup | β |
@yearly / @annually | Once a year | 0 0 1 1 * |
@monthly | Once a month | 0 0 1 * * |
@weekly | Once a week | 0 0 * * 0 |
@daily / @midnight | Once a day | 0 0 * * * |
@hourly | Once an hour | 0 * * * * |
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 * 1runs on the 1st of the month and every Monday β not βMondays that are the 1stβ. This is the single most misunderstood cron rule. */5vs5. 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.
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.