Cron syntax cheat sheet
Cron is the Unix scheduler that runs commands on a repeating timetable. A crontab line is five fields followed by the command, and almost every cron mistake comes from misreading one of those five fields. Here is the whole syntax, the schedules worth memorising, and the point where you should reach for a systemd timer instead.
The five fields
Fields are separated by spaces, in this order. A sixth field can be prepended on systems that support seconds (Quartz-style schedulers and some crontab implementations).
| Field | Range | Notes |
|---|---|---|
| minute | 0–59 | The first field, not the hour. |
| hour | 0–23 | 24-hour clock, in the server's time zone. |
| day of month | 1–31 | Days that do not exist in a month are skipped. |
| month | 1–12 or JAN–DEC | Names are case-insensitive. |
| day of week | 0–7 or SUN–SAT | 0 and 7 both mean Sunday. |
Operators
-
*— every value in the field, e.g.* * * * *is every minute. 5— one value.1-5— a range, inclusive.-
*/15— a step;*/15in the minute field means every 15 minutes. 10-40/10— a range with a step.1,15— a list; combine any of the above with commas.
The day-of-month/day-of-week quirk
When both day fields are restricted, classic cron treats them as an OR, not an AND.
0 3 13 * FRI runs on the 13th of the month and every Friday, not only on Friday
the 13th. If you need that AND, put the check in the command itself or use a scheduler with a clearer
expression language.
How it differs from a systemd timer
Both run a unit on a schedule, but they are not the same tool. Cron is a daemon reading
crontab files, one line per job, with no dependency awareness and no catch-up. Systemd timers
are an ordinary unit pair: a .timer that says when, and a .service that
says what.
| Aspect | cron | systemd timer |
|---|---|---|
| Calendar syntax | */5 * * * * | OnCalendar=*:0/5 |
| Interval timers | Achieved by a step field | OnUnitActiveSec=30min — monotonic, independent of wall-clock jumps |
| Missed runs (machine asleep) | Lost | Persistent=true runs once on the next boot |
| Logging | Mails output, or you redirect it yourself | Captured in the journal by default |
| Dependencies | None | After=, Requires=, full unit ordering |
| Random jitter | Manual | RandomizedDelaySec= |
Schedules worth memorising
| Expression | Meaning |
|---|---|
* * * * * | Every minute |
*/5 * * * * | Every 5 minutes |
0 * * * * | At the top of every hour |
30 3 * * * | Daily at 03:30 |
0 9-17 * * MON-FRI | On the hour, 09:00–17:00, weekdays |
15 2 * * 0 | Sunday at 02:15 |
0 0 1 * * | Midnight on the first of each month |
0 4 1,15 * * | 04:00 on the 1st and 15th |
Shorthand keywords
Most crontabs accept a handful of words that expand to common schedules: @reboot (once at startup), @hourly, @daily (or @midnight), @weekly, @monthly and @yearly. They are convenient and readable, though not part of the original POSIX
specification, so check that your cron implementation supports them.
Time zones matter more than people expect
The clock cron uses is the local time of the machine, not UTC, unless you say otherwise.
0 3 * * * therefore runs at 03:00 in the server's zone and shifts by an hour when daylight
saving changes — and a job scheduled inside a skipped hour simply does not run that day. For anything
that must be predictable, pin the zone explicitly (many crontabs accept a CRON_TZ= or TZ= line, and systemd timers accept a zone in the calendar
expression) and prefer UTC on servers.
Check an expression before you ship it
A scheduler that fires at the wrong instant is worse than one that never fires, because you only find out from the damage. The cron expression parser turns an expression into plain English and lists its next run times in UTC, so a misread field shows up as an obviously wrong timestamp. If you would rather build the expression from a form, the crontab generator assembles it for you.
Common mistakes
-
Assuming the hour comes first. It is minutes, then hours —
30 8is 08:30. -
Forgetting that cron gets a minimal environment: your
PATH, aliases and shell profile are not loaded, so use absolute paths and set variables in the crontab itself. -
Expecting a working directory.
cd /path && ./job.shis safer than hoping. - Dropping output on the floor and losing errors, or the opposite — letting cron mail the output of a chatty job. Redirect it deliberately.
-
Forgetting that
%is special inside a crontab: an unescaped percent becomes a newline and is fed to the command's standard input, so escape it as\%when you mean the character.
More guides
- Base64 explained — what Base64 is and where it belongs.
- Which hash should I use? — digests, passwords and HMAC.
- Colour contrast and WCAG — accessible colour choices.