Cron expression examples explained
Learn how the five cron fields work, with worked examples, the day-of-month trap, time zone pitfalls and common mistakes.
By the tools4free.dev team · Last reviewed 4 December 2026
A standard cron expression has five fields separated by spaces: minute, hour, day of month, month and day of week. The scheduler runs your command whenever the current time matches all five, with one quirk for the two day fields that is covered below. For example, 30 2 * * 1-5 means "at 02:30, Monday to Friday".
The five fields
| Position | Field | Allowed values |
|---|---|---|
| 1 | Minute | 0-59 |
| 2 | Hour | 0-23 |
| 3 | Day of month | 1-31 |
| 4 | Month | 1-12 (many implementations also accept JAN-DEC) |
| 5 | Day of week | 0-6 for Sunday to Saturday (many implementations also accept 7 for Sunday and SUN-SAT) |
The POSIX specification for crontab defines the numeric ranges above. Names, the value 7 and shortcuts such as @daily are extensions that Vixie cron and its descendants support, so check your own system's man 5 crontab before relying on them.
The four operators
*means every value in the field's range.,separates a list:1,15in the day-of-month field means the 1st and the 15th.-is an inclusive range:9-17in the hour field means 09:00 to 17:59 when the minute field is*./is a step, an extension to POSIX that is almost universal:*/15in the minute field means 0, 15, 30 and 45. A step can follow a range:0-30/10means 0, 10, 20 and 30.
Worked example 1: common schedules
These are the schedules people ask for most often. Read each one field by field.
| Expression | Meaning |
|---|---|
* * * * * | Every minute |
*/15 * * * * | Every 15 minutes, on the quarter hour |
0 * * * * | At minute 0 of every hour |
30 2 * * * | Every day at 02:30 |
0 9 * * 1-5 | 09:00 on weekdays |
0 0 * * 0 | Midnight at the start of Sunday |
0 9 1 * * | 09:00 on the 1st of each month |
0 0 1 1 * | Midnight on 1 January |
0 8,12,18 * * * | 08:00, 12:00 and 18:00 every day |
*/10 9-17 * * 1-5 | Every 10 minutes from 09:00 to 17:50, weekdays |
Note the last row. The hour range 9-17 includes the whole of hour 17, so the final run is at 17:50, not 17:00. If you want the last run at exactly 17:00, use two entries: */10 9-16 * * 1-5 and 0 17 * * 1-5.
Worked example 2: a crontab file
You edit your own schedule with crontab -e. Each line is five time fields followed by the command. Here is a small crontab for a web server:
# m h dom mon dow command
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=ops@example.com
# Rotate application logs at 03:15 every day
15 3 * * * /usr/local/bin/rotate-logs.sh >> /var/log/rotate.log 2>&1
# Sync reports every 30 minutes during office hours
*/30 8-18 * * 1-5 /usr/local/bin/sync-reports.sh
# Monthly invoice run at 06:00 on the 1st
0 6 1 * * /usr/local/bin/invoices.sh
# Percent signs must be escaped in the command part
0 1 * * * tar -czf /backup/site-$(date +\%F).tgz /var/www
Three details matter here. First, cron runs jobs with a minimal environment, so set PATH at the top or use absolute paths. Second, the >> file 2>&1 redirect captures both output streams; without it, cron tries to email the output to MAILTO or the local user. Third, an unescaped % in a crontab command is treated as a newline, so date +%F must be written date +\%F.
The day-of-month and day-of-week rule
This is the most surprising behaviour in cron. When both the day-of-month and day-of-week fields are restricted (neither is *), POSIX and Vixie cron run the job when either matches, not both. So 0 9 13 * 5 does not mean "09:00 on Friday the 13th". It means "09:00 on the 13th of every month, and also on every Friday".
If you really need "the first Monday of the month", a common pattern is to restrict only the day-of-week field in the schedule and test the date in the command:
0 9 * * 1 [ "$(date +\%d)" -le 7 ] && /usr/local/bin/monthly-review.sh
The job fires every Monday, and the shell test lets it through only when the day of the month is 7 or less. That is always the first Monday.
Time zones and daylight saving
Classic cron uses the time zone of the machine (or, for some implementations, of the cron daemon's environment). It does not know about your users' time zones. Two consequences:
- On servers that use UTC,
0 9 * * *is 09:00 UTC, which is a different local time in summer and winter for most of the world. - On servers that use a local zone with daylight saving time, a job scheduled inside the skipped hour in spring may not run, and a job scheduled inside the repeated hour in autumn may run twice or once, depending on the implementation. Avoid scheduling important jobs between 01:00 and 03:00 local time on those servers, or run the server in UTC.
Cron variants
Not every tool that accepts "cron syntax" accepts the same syntax. Check which dialect you are writing for.
| Dialect | Difference from the five-field standard |
|---|---|
| Quartz (Java) | Six or seven fields: a leading seconds field and an optional trailing year. Uses ? for "no specific value" in one of the day fields. |
Spring @Scheduled | Six fields with seconds first. |
| Kubernetes CronJob | Standard five fields, plus an optional time zone field in the spec. |
GitHub Actions schedule | Standard five fields, always evaluated in UTC. |
| systemd timers | Not cron at all. Uses OnCalendar= expressions such as Mon..Fri 09:00. |
Common mistakes
- Using
*in the minute field by accident.* 3 * * *runs every minute between 03:00 and 03:59, which is 60 runs, not one. For once an hour, put a number in the minute field. - Expecting
*/7to mean "every seven minutes" forever. The step restarts at the top of each hour: it fires at 0, 7, 14 and so on up to 56, then again at 0. The gap between 56 and 0 is only 4 minutes. - Scheduling on day 31.
0 0 31 * *only runs in months that have 31 days. For "last day of the month", schedule daily and test tomorrow's date in the command. - Relying on your shell profile. Cron does not read
.bashrc, so commands that work in your terminal can fail in cron with "command not found". - Letting jobs overlap. A job that takes longer than its interval starts a second copy. Use
flockor a lock file. - Forgetting the trailing newline. Some crontab implementations ignore a last line that does not end with a newline.
Frequently asked questions
How do I run a job every 5 seconds?
You cannot with standard cron, because its resolution is one minute. Use a systemd timer, a loop with sleep inside a service, or a scheduler that supports a seconds field.
What does @reboot do?
It is a Vixie cron extension that runs the command once when the cron daemon starts, typically at boot. Other shortcuts are @hourly, @daily, @weekly, @monthly and @yearly.
Why did my job not run?
Check, in order: the crontab syntax (crontab -l), the system log for CRON entries, the PATH and environment, file permissions on the script, and whether the script is executable. Run the exact command as the cron user with env -i to reproduce the minimal environment.
Can I run a job on the last Friday of the month?
Not directly. Schedule it for every Friday and have the command exit unless the date plus seven days falls in the next month.
Try it: build and check an expression with the cron expression builder, which shows what each field means in plain English.