Cron is the classic Unix job scheduler, and its compact expressions — like 30 2 1-5 — have spread far beyond Unix. Backups, report emails, data imports, cache clearing, subscription renewals and cleanup jobs on servers and in cloud schedulers are all commonly scheduled with cron syntax or something close to it.
A cron expression is short, which is both its strength and its danger. One wrong character can mean a job runs every minute instead of every month, or never runs at all. This guide explains the standard syntax, the rules that trip people up, and how to check a schedule before trusting it. You can test every example with our cron expression builder.
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 or JAN–DEC)
│ │ │ │ ┌ day of week (0–6 or SUN–SAT; 7 is also Sunday in many implementations)
│ │ │ │ │
30 2 * * 1-5
That example means “at 02:30, Monday to Friday”. In a traditional crontab file, the command to run follows the five fields on the same line.
Hours use the 24-hour clock, so 2 means 2 a.m. and 14 means 2 p.m.
Special characters
| Character | Meaning | Example | Reads as |
|---|---|---|---|
* | Every value | * | Every minute |
, | A list | 0 9,13,17 * | At 09:00, 13:00 and 17:00 |
- | A range | 0 9 1-5 | At 09:00, Monday to Friday |
/ | A step | /15 * | Every 15 minutes |
| Names | Months and days | 0 0 1 JAN * | Midnight on 1 January |
Steps can apply to ranges: 0 8-18/2 * means every two hours from 08:00 to 18:00 (08:00, 10:00, 12:00, 14:00, 16:00 and 18:00).
A step on starts from the lowest value of the field, so /15 in the minute field means minutes 0, 15, 30 and 45 — not “15 minutes after the job last ran”.
Examples you can copy
Each of these follows standard five-field cron.
| Expression | Runs |
|---|---|
* | Every minute |
/5 * | Every 5 minutes |
0 | At the start of every hour |
15 | At 15 minutes past every hour |
0 0 * | Every day at midnight |
30 6 * | Every day at 06:30 |
0 9 1-5 | Weekdays at 09:00 |
0 18 5 | Fridays at 18:00 |
0 3 0 | Sundays at 03:00 |
0 0 1 | Midnight on the first day of every month |
0 12 1,15 | Noon on the 1st and 15th of every month |
0 0 1 1 * | Midnight on 1 January |
0 /6 | Every 6 hours (00:00, 06:00, 12:00, 18:00) |
0 9-17 1-5 | On the hour, 09:00 to 17:00, on weekdays |
Macros
Many cron implementations accept shortcuts:
| Macro | Equivalent |
|---|---|
@yearly or @annually | 0 0 1 1 * |
@monthly | 0 0 1 |
@weekly | 0 0 0 |
@daily or @midnight | 0 0 * |
@hourly | 0 |
@reboot | Once, when the cron service starts |
Check that your scheduler supports them before relying on them.
The rule that surprises everyone: day of month and day of week
In standard (Vixie-style) cron, the day-of-month and day-of-week fields interact in an unusual way.
- If either field is unrestricted (starts with
*), a day must match both fields — which in practice means just the restricted one. - If both fields are restricted, the job runs when either matches.
So 0 0 13 * 5 does not mean “Friday the 13th”. It means “midnight on the 13th of every month, and midnight every Friday”.
This catches out experienced developers. If you need “the first Monday of the month”, standard cron can’t express it directly. Common workarounds are to schedule the job for Mondays and have the script exit unless the date is between the 1st and 7th, or to use a scheduler with richer syntax.
Our cron builder follows the standard rule and shows the next run times, so you can see the effect immediately.
Time zones and daylight saving time
Cron runs in a time zone, and that is a frequent source of bugs.
- On a traditional server, cron usually uses the system time zone. Some implementations support a
CRON_TZvariable; cloud schedulers often have a time-zone setting. - Many teams run servers in UTC to avoid surprises, then convert schedules from local business hours.
- Daylight saving time creates gaps and repeats. When clocks jump forward, times in the skipped hour don’t exist; when clocks go back, an hour happens twice. Depending on the implementation, a job scheduled in that hour may run once, twice or not at all.
Practical advice:
- Know which time zone each scheduler uses, and write it next to the expression.
- Avoid scheduling important jobs between roughly 01:00 and 03:00 local time in zones that observe daylight saving, as that is when transitions commonly happen in many regions.
- If a job must run at a specific local business time across daylight saving changes, use a scheduler that supports named time zones such as
Europe/London, rather than a fixed UTC offset.
Our timestamp converter and time zone meeting planner help you translate times between zones. For the bigger picture, see our guide to timestamps and time zones.
Variations you’ll meet
Cron syntax isn’t perfectly standard. Before copying an expression between systems, check which flavour each uses.
- Seconds field. Some schedulers, including Quartz-style and Spring-style schedulers, add a seconds field at the start, giving six fields.
- Year field. Some formats add an optional seventh field for the year.
- Extra symbols. Quartz-style syntax supports
?(no specific value),L(last, as in the last day of the month),W(nearest weekday) and#(such as the third Friday). Standard cron does not. - Cloud schedulers. Some cloud providers use their own variants, for example requiring
?in one of the day fields. Read the provider’s documentation. - Day-of-week numbering. In standard cron, 0 and 7 are Sunday. Some other formats number days 1–7 starting on Sunday. A copied expression can silently shift by a day.
Common mistakes
- A star in the minute field.
2runs every minute between 02:00 and 02:59 — 60 times — not once at 2 a.m. You almost certainly meant0 2 *. - Confusing the field order. Day of month comes before month:
0 0 12 1 *is 12 January, not 1 December. - Assuming
/nrestarts from the last run. Steps are aligned to the field’s values, not to when the job last ran./7in the minute field runs at 0, 7, 14 … 56 and then 0 again, giving a 4-minute gap at the top of the hour. - Ignoring the environment. Cron jobs often run with a minimal set of environment variables and a different working directory. Use full paths and set what the job needs.
- No logging or alerting. A job that fails silently can go unnoticed for months. Log output, and alert on failures or on jobs that stop running.
- Overlapping runs. If a job sometimes takes longer than its interval, two copies may run at once. Use a lock to prevent overlap.
Checking a schedule before you deploy it
A few minutes of checking prevents most cron surprises.
- Read it back in words. Paste the expression into the cron expression builder and read the plain-English description. If it doesn’t say what you meant, the expression is wrong.
- Look at the next run times. Check that the next five or ten runs fall on the days and times you expect, especially around month ends and weekends.
- Confirm the time zone. The builder shows times in your browser’s zone; your server or cloud scheduler may use UTC or another zone. Convert if needed.
- Start with a harmless test. Run the job manually, or schedule it a few minutes ahead with logging only, before letting it touch real data or send emails.
- Write a comment next to the entry in plain words, such as “Daily sales report, 06:30 UTC, owner: finance team”. The next person to read the crontab will thank you.
Cron in a crontab file
On Linux and other Unix-like systems, each user can have a crontab, edited with crontab -e. Each line has the five schedule fields followed by the command:
# m h dom mon dow command
30 2 * * 1-5 /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
A few practical notes:
- Lines starting with
#are comments. - Redirecting output to a log file (as above) keeps a record of each run and any errors.
- Some systems also have a system-wide crontab, such as
/etc/crontab, where an extra field before the command names the user the job runs as. - Many hosting control panels provide a form for cron jobs that writes these lines for you, using the same five fields.
Making scheduled jobs reliable
A cron expression only decides when something starts. Reliability comes from what surrounds it:
- Make jobs idempotent, so running one twice by accident doesn’t duplicate data or emails.
- Use locks to prevent overlapping runs.
- Log start, finish and errors somewhere you will actually look.
- Monitor with a “dead man’s switch” — a check that alerts you if a job doesn’t report in on time.
- Document each job: what it does, its schedule and time zone, and who owns it.
Scheduled jobs are part of the routine operations covered by good website maintenance plans. If you need help designing reliable background jobs, queues and monitoring, our cloud and DevOps team does exactly that. Terms such as cron, UTC and webhook are defined in our web development glossary.
Frequently asked questions
What does * mean in cron?
It means “every minute of every hour of every day”. Each star stands for “every value” in its field: minute, hour, day of month, month and day of week.
How do I run a cron job every 5 minutes?
Use /5 *. It runs at minutes 0, 5, 10 and so on, every hour.
How do I schedule a job for weekdays only?
Put 1-5 in the day-of-week field. For example, 0 9 1-5 runs at 09:00 Monday to Friday.
Why did my job run on the wrong day?
The most common cause is restricting both day of month and day of week. In standard cron the job then runs when either matches. Another common cause is a different time zone on the server, or a scheduler that numbers days of the week differently.
Does cron handle seconds?
Standard five-field cron doesn’t. Its smallest unit is one minute. Some schedulers add a seconds field; if you need sub-minute timing, check your platform’s scheduler or use a long-running worker instead.