What Is a Cron Expression? Syntax, Examples, and a Free Generator

A cron expression is a five-field string that tells a computer when to run a scheduled task: minute, hour, day of the month, month, and day of the week. For example, 0 9 * * 1-5 runs a job at 9:00am on weekdays. You write one whenever you need something to happen on a schedule — a backup every night, a report every Monday, a cleanup script every hour.

Cron has scheduled jobs on Unix-like systems for decades, and the syntax has barely changed in all that time. It takes about five minutes to learn and a lifetime to look up: almost nobody remembers whether the day of the week comes before or after the month. This guide is the lookup page — the syntax field by field, 15 schedules you can copy, and the two traps that make jobs run at the wrong time.

Desk calendar and laptop set up for scheduling

Cron Syntax: The 5 Fields, Explained One by One

A cron expression is five fields separated by spaces, followed by the command to run. The order never changes:

*  *  *  *  *  command
|  |  |  |  |
|  |  |  |  +-- day of week   (0-7, both 0 and 7 are Sunday)
|  |  |  +----- month         (1-12)
|  |  +-------- day of month  (1-31)
|  +----------- hour          (0-23)
+-------------- minute        (0-59)
Field Allowed values Notes
Minute 0–59 0 is the top of the hour.
Hour 0–23 24-hour clock. There is no hour 24; midnight is 0.
Day of month 1–31 A day the month does not have, like 31 in April, is skipped.
Month 1–12 or JAN–DEC Names are the first three letters, case-insensitive.
Day of week 0–7 or SUN–SAT Both 0 and 7 mean Sunday on Linux.

Read a cron expression left to right, small unit to large, with the weekday last. 30 2 * * * reads as: minute 30, hour 2, every day of the month, every month, every day of the week — 02:30 every day. The asterisks mean “every value”, so a field set to * places no restriction at all.

Everything after the fifth field is the command, which cron runs with /bin/sh unless the crontab sets a different shell. In your own crontab (edited with crontab -e), the command follows the five fields directly. In the system crontab at /etc/crontab and files under /etc/cron.d/, there is an extra username field between the schedule and the command.

Linux cron also accepts shortcuts that replace all five fields: @hourly, @daily, @weekly, @monthly, @yearly, and @reboot (runs once when the machine starts). They are handy, but they hide the exact time — @daily runs at midnight, which may not be when you want it.

15 Common Cron Expressions You Can Copy

Every expression below was checked field by field against the ranges in the table above.

Expression When it runs
* * * * * Every minute
*/5 * * * * Every 5 minutes
0 * * * * Every hour, on the hour
0 9 * * * Every day at 09:00
0 0 * * * Every day at midnight
30 2 * * * Every day at 02:30
0 9 * * 1-5 Weekdays (Monday to Friday) at 09:00
0 18 * * 5 Every Friday at 18:00
0 0 * * 0 Every Sunday at midnight
0 0 1 * * On the 1st of every month, at midnight
0 0 15 * * On the 15th of every month, at midnight
0 6 1 1 * On 1 January at 06:00, once a year
0 0 * * 1,3,5 Monday, Wednesday, and Friday at midnight
*/15 9-17 * * 1-5 Every 15 minutes between 09:00 and 17:59, weekdays
0 0 1 */3 * On the 1st of January, April, July, and October, at midnight

A note on */15 9-17 * * 1-5: the hour range 9–17 means the job runs at 09:00, 09:15, and so on up to 17:45. It does not run at 18:00, because 18 is outside the range. Ranges are inclusive of both ends, which is easy to forget when the end value is a boundary like 17.

Server racks in a data centre

Special Characters: * , – / and What They Do

Four characters do all the work in cron expressions:

  • * (asterisk) — every value. * in the hour field means every hour. An expression of all asterisks runs every minute.
  • , (comma) — a list of values. 1,15 in the day-of-month field means the 1st and the 15th. 1,3,5 in the day-of-week field means Monday, Wednesday, and Friday.
  • - (hyphen) — a range, inclusive at both ends. 1-5 in the day-of-week field is Monday through Friday. 9-17 in the hour field is 09:00 through 17:59.
  • / (slash) — a step value. */5 in the minute field means every 5 minutes: 0, 5, 10, and so on. */4 in the hour field means every 4 hours: 0, 4, 8, 12, 16, 20. You can also step through a range, like 0-30/10 for minutes 0, 10, 20, and 30.

You can combine them: 0 8,12,18 * * * runs at 08:00, 12:00, and 18:00 every day. Month and weekday fields also accept three-letter names — mon,wed,fri and jan-mar work, and the case does not matter — but numbers are less ambiguous, and every cron implementation understands numbers. Step values and names are extensions beyond the original POSIX spec, so check your system’s manual if you are on an unusual platform.

Day of Month vs Day of Week: The Classic Mistake

Here is the trap that catches almost everyone at least once. When both day fields are restricted — neither one is * — standard cron runs the job when either field matches, not when both match. The crontab(5) manual is explicit about this, and it is the opposite of what most people expect.

So 0 0 1 * 1 does not mean “midnight on the first Monday of the month”. It means “midnight on the 1st of the month and midnight on every Monday”. In a typical year that fires about 60 times, not 12.

The rule is actually three rules:

  • Day of month restricted, day of week * — only the date decides. 0 0 15 * * runs on the 15th.
  • Day of week restricted, day of month * — only the weekday decides. 0 0 * * 1 runs on Mondays.
  • Both restricted — either one matching runs the job.

There is no way to express “the first Monday of the month” with the five fields alone. The standard workaround is to restrict the day of month to the first seven days, leave the weekday as *, and test the weekday inside the command:

0 0 1-7 * * [ "$(date +\%u)" = "1" ] && /usr/local/bin/monthly-report.sh

The 1-7 range limits the job to the first week of the month, and date +%u returns the weekday as a number from 1 (Monday) through 7 (Sunday). The script runs only when both are true. Note the backslash before %: cron treats an unescaped % as a newline, so \% is required inside a crontab line.

Timezones and Daylight Saving Gotchas

Cron runs on the server’s local time, not UTC and not your time. If your server is set to UTC and you are in Karachi (UTC+5), a job scheduled for 0 9 * * * runs at 14:00 your time. Before you debug a job that “runs at the wrong time”, check the server’s timezone with timedatectl or date — the schedule is usually fine; the clock is somewhere else.

Some cron implementations let a crontab set its own zone. Cronie, the cron used on Red Hat-family systems, supports a CRON_TZ variable at the top of the crontab, which makes that crontab’s lines use the given zone. Vixie cron on Debian and Ubuntu does not support it — there, the daemon’s timezone decides for every job.

Daylight saving adds two more wrinkles. In spring, when clocks jump forward, an hour of local time never happens — a job scheduled inside the skipped hour does not run that day. In autumn, when clocks fall back, an hour happens twice, and a job scheduled inside the repeated hour can run twice. If your jobs must run exactly once a day, schedule them outside the usual 01:00–03:00 DST transition window, or run the server on UTC and convert in your head.

Close-up of an analogue clock face

Build Your Expression With the Free Generator

If you would rather not assemble the five fields by hand, the free cron expression generator builds the expression from plain choices — every hour, daily at a time you pick, weekdays only — and shows the result ready to paste into your crontab. It is a good way to double-check an expression you wrote by hand, too: if the generator’s plain-English reading of your schedule does not match what you intended, the expression is wrong, not the generator.

Weekly planner and notebook on a desk

Two habits will save you from most cron failures. First, test the command itself before scheduling it: run it by hand from a bare shell, because cron’s environment is almost empty compared with your login shell — a different PATH, no aliases, no loaded profile. Use full paths to scripts and binaries. Second, after adding a job, check that it actually ran. Cron logs to the system log on most Linux systems, so a quick look at /var/log/syslog or journalctl -u cron after the first scheduled run tells you whether it fired.

And if your scheduled job deals with times as numbers rather than clock readings — logging timestamps, expiry checks, API fields — the Unix timestamp converter turns epoch seconds into readable dates and back.

Frequently Asked Questions

What is a cron expression?

A cron expression is a five-field string — minute, hour, day of month, month, day of week — that defines when a scheduled job runs. 0 9 * * 1-5 means 09:00 on weekdays. It comes from cron, the job scheduler on Unix-like systems.

How do I write a cron expression for every day at midnight?

0 0 * * * — minute 0, hour 0, every day of the month, every month, every day of the week. The shortcut @daily does the same thing.

What does */5 mean in a cron expression?

Every 5 units of that field. */5 in the minute field runs every 5 minutes (at :00, :05, :10, and so on). */2 in the hour field runs every 2 hours.

Why does my cron job run on the wrong days?

The most common cause is the day-of-month/day-of-week rule: when both fields are restricted, cron runs the job when either matches, not both. 0 0 1 * 1 runs on the 1st of the month and on every Monday. The second most common cause is the server’s timezone differing from yours.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top