Home › Guides › Developer › Cron expression examples explained

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

PositionFieldAllowed values
1Minute0-59
2Hour0-23
3Day of month1-31
4Month1-12 (many implementations also accept JAN-DEC)
5Day of week0-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

Worked example 1: common schedules

These are the schedules people ask for most often. Read each one field by field.

ExpressionMeaning
* * * * *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-509:00 on weekdays
0 0 * * 0Midnight 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-5Every 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:

Cron variants

Not every tool that accepts "cron syntax" accepts the same syntax. Check which dialect you are writing for.

DialectDifference 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 @ScheduledSix fields with seconds first.
Kubernetes CronJobStandard five fields, plus an optional time zone field in the spec.
GitHub Actions scheduleStandard five fields, always evaluated in UTC.
systemd timersNot cron at all. Uses OnCalendar= expressions such as Mon..Fri 09:00.

Common mistakes

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.

Sources