Cron Syntax Explained: The 5 Fields Made Easy
Cron syntax is a five-field time format that tells Linux exactly when to run a command. Once you can read those five fields, every cron expression becomes obvious. Here is the layout you will use every time:
* * * * * command to run
│ │ │ │ │
│ │ │ │ └─ Day of week (0–7, Sun=0 or 7)
│ │ │ └─── Month (1–12)
│ │ └───── Day of month (1–31)
│ └─────── Hour (0–23)
└───────── Minute (0–59)
Read left to right: minute, hour, day of month, month, day of week, then the command. Master this and the rest is detail. Let's break down each part of the crontab syntax with correct, copy-ready examples.
The Five Cron Fields
Each of the five positions accepts a number in a fixed range. An asterisk (*) means "every value" for that field.
| Field | Allowed values | Meaning |
|---|---|---|
| Minute | 0–59 | Minute of the hour |
| Hour | 0–23 | Hour in 24-hour time |
| Day of month | 1–31 | Calendar day |
| Month | 1–12 (or Jan–Dec) | Month of year |
| Day of week | 0–7 (or Sun–Sat) | Weekday |
A simple example — run a script at 6:00 a.m. every day:
0 6 * * * /home/sam/morning.sh
Minute 0, hour 6, any day, any month, any weekday. That is the entire cron time format in one line.
Cron Special Characters
The real power of cron syntax comes from a handful of special characters that combine values.
Asterisk (*) — every value
Matches all values in the field.
* * * * * /path/task.sh # every minute
Comma (,) — a list of values
Run at several specific times.
0 8,12,18 * * * /path/task.sh # 8am, 12pm, 6pm
Hyphen (-) — a range
Run across a continuous span.
0 9-17 * * 1-5 /path/task.sh # top of every hour, 9am–5pm, Mon–Fri
Slash (/) — step values
Run at regular intervals within a range.
*/15 * * * * /path/task.sh # every 15 minutes
0 */2 * * * /path/task.sh # every 2 hours
*/15 in the minute field means "starting at 0, every 15 minutes" — so 0, 15, 30, 45. Steps can also apply to a range: 0-30/10 means 0, 10, 20, 30, and 5-30/5 means minutes 5, 10, 15, 20, 25, 30.
Named Values and Shortcuts
Cron accepts three-letter names for months and weekdays, which many people find easier to read:
0 0 * * MON /path/weekly.sh # every Monday at midnight
0 0 1 JAN * /path/newyear.sh # January 1st at midnight
There are also special string shortcuts that replace all five fields:
| Shortcut | Equivalent | Meaning |
|---|---|---|
@reboot | — | Once at startup |
@yearly / @annually | 0 0 1 1 * | Once a year |
@monthly | 0 0 1 * * | First of the month |
@weekly | 0 0 * * 0 | Every Sunday |
@daily / @midnight | 0 0 * * * | Every day at midnight |
@hourly | 0 * * * * | Top of every hour |
Example:
@daily /home/sam/backup.sh
A Note on Six-Field Variants
Not every "cron expression" has exactly five fields, and knowing the variants saves confusion:
- The system crontab (
/etc/crontaband files in/etc/cron.d/) inserts a username between the schedule and the command:0 3 * * * root /usr/local/bin/backup.sh. Paste a five-field entry there and cron will try to run a command named after your minute value. - Quartz-style expressions (Java, Spring, some SaaS schedulers) prepend a seconds field, producing six or seven fields.
0 0/5 * * * ?is Quartz, not crontab — the two are not interchangeable.
When a tool asks for "cron syntax," check which dialect it means before copying an expression across.
Common Cron Syntax Mistakes
These gotchas catch nearly everyone at least once.
- The 0-and-7 Sunday rule. In the day-of-week field, both
0and7mean Sunday. Do not assume 7 is invalid. - Day-of-month vs day-of-week is an OR, not an AND. If you set both fields (neither is
*), cron runs when either matches. For example,0 0 13 * 5runs on the 13th of every month and on every Friday — not only on Friday the 13th. */5always starts at zero.*/5fires at 0, 5, 10… If you need 2, 7, 12…, list the minutes explicitly:2,7,12,17,22,27,32,37,42,47,52,57.- Percent signs need escaping. In a crontab command, an unescaped
%becomes a newline. Escape it as\%when calling programs likedate. - Every field must be present. There is no "run every 90 seconds" in standard cron; the finest resolution is one minute.
Reading a Cron Expression Step by Step
Let's decode one:
30 3 1,15 * * /opt/reports/generate.sh
- Minute:
30 - Hour:
3 - Day of month:
1,15 - Month:
*(every) - Day of week:
*(every)
Result: run at 3:30 a.m. on the 1st and 15th of every month. Working through the fields in order makes any cron expression readable.
Best Practices for Writing Cron Syntax
- Validate before you save. Paste your expression into crontab.guru to confirm it means what you think it means.
- Comment your jobs. Add a
#line above each entry explaining its purpose and owner. - Use absolute paths for commands, since cron runs with a minimal environment.
- Prefer shortcuts like
@dailyfor readability when exact timing does not matter. - Test the command manually in your shell before you automate it.
Conclusion
Cron syntax is just five time fields plus a command, sharpened by a few special characters: * for every, , for lists, - for ranges, and / for steps. Learn those and you can schedule almost anything. Watch out for the Sunday and day-of-month gotchas, always use absolute paths, and validate expressions before saving.
Ready to put this into practice? Grab ready-to-use jobs from our crontab examples library, or follow our step-by-step guide to set up your first cron job on Linux.
Frequently Asked Questions
What does * * * * * mean in cron?
It means "run every minute of every hour, every day." All five fields are wildcards, so the command executes once per minute continuously.
How do I run a cron job every 15 minutes?
Use a step value in the minute field: */15 * * * *. This runs the command at minutes 0, 15, 30, and 45 of every hour.
What is the difference between day of month and day of week in cron?
They are the third and fifth fields. If you set both to specific values, cron runs when either matches (an OR), not only when both match — a frequent source of confusion.
Are the days of the week 0-based in cron?
Yes. Sunday is 0, Monday is 1, up to Saturday which is 6. As a special case, 7 also means Sunday, so both 0 and 7 are valid.
Need the expression itself? Build and test any cron schedule in our free visual generator — with live upcoming-run previews in Unix and Quartz formats.
Related guides
References
- man7.org — crontab(5) manual page — the definitive field and character reference
- crontab.guru — live cron expression editor and tester
- Red Hat documentation — Automating system tasks — enterprise-grade cron guidance