Developer

How to Write Cron: The 5 Fields, Symbols, and crontab Examples Explained

Cron is the classic way to run a task automatically at a set time. This guide walks beginners through what cron is, the meaning of the five fields that make up the syntax, how to use symbols like * / , -, common examples such as daily, hourly, and weekly schedules, and the pitfalls you are likely to hit when setting it up.

Published: 2026-10-16

"I want a backup every night." "I want to aggregate logs every hour." Doing these recurring tasks by hand is not realistic. The classic mechanism for automatic execution on Linux and macOS is cron. At first it looks like a jumble of numbers and symbols, but the syntax is nothing more than a combination of five fields. This article explains how to write cron step by step for first-time users.

What Is Cron

Cron is a scheduler for recurring execution built into UNIX-like operating systems such as Linux and macOS. A background program called crond checks the registered schedule every minute and automatically runs any command whose time matches.

The configuration file that lists the schedules is called a crontab (cron table). You edit your own crontab with the command crontab -e and view it with crontab -l. Each line corresponds to one job and looks like this.

* * * * * the command to run

The five * at the start of the line are the schedule part that says "when to run," and the actual command follows. How you write these five fields is the key to using cron well.

Cron suits a wide range of recurring work, such as the following.

  • Backups: copy databases or files aside every night.
  • Aggregation and reports: total up logs every hour or each morning.
  • Maintenance: regularly delete temporary files or clear caches.
  • Notifications: send a reminder to email or chat at a set time.

The Meaning of the Five Fields

The schedule part consists of five fields, from left to right: minute, hour, day of month, month, and day of week. The range each can take is as follows.

PositionFieldAllowed range
1stminute0-59
2ndhour0-23 (24-hour clock)
3rdday of month1-31
4thmonth1-12
5thday of week0-7 (0 and 7 are Sunday, 1 is Monday)

For example, 30 9 * * * means minute=30, hour=9, and the rest unspecified, so it runs every day at 9:30. The trick to reading it is to apply, from the left, "what minute, what hour, what day, what month, what weekday" in order.

Time uses the 24-hour clock, so 3 p.m. is written as 15. The weekday is given as a number, where 0 or 7 is Sunday, 1 is Monday, and so on up to 6 for Saturday. Depending on the environment you can also use three-letter English names like sun or mon, and jan or feb for months, but numbers are safest for compatibility.

0 0 1 * * → minute=0, hour=0, day=1, that is, run at 0:00 on the 1st of every month

Note that when you specify both day of month and day of week, most cron implementations treat it as an OR condition: "run if either one matches." This is easy to get wrong, so it is covered again in the pitfalls below.

Using the Symbols (* / , -)

Each field accepts not only numbers but also symbols that express repetition or ranges. There are four symbols to learn.

SymbolMeaningExample
*all values (every time)* in the hour field means every hour
/interval (every N)*/5 is every 5 minutes
,multiple values (list)0,30 is at minute 0 and 30
-range9-17 is from 9 to 17 o'clock

The asterisk (*) means "no condition on this field, that is, every time." Setting all five to * with * * * * * gives the shortest interval, running every minute.

The slash (/) expresses an interval of "every N." In the minute field, */15 means minute 0, 15, 30, and 45, that is, every 15 minutes. Writing */2 in the hour field makes it every two hours.

The comma (,) lists values. 0,15,30,45 gives the same result as */15, but it is handy when you want irregular times such as 8,12,18.

The hyphen (-) expresses a continuous range. In the weekday field, 1-5 means Monday through Friday (weekdays). These can be combined too: 0-30/10 means "every 10 minutes between minute 0 and 30 (0,10,20,30)."

Common Examples

Combining the building blocks so far lets you write practical schedules. Let us look at representative examples. The command part is abbreviated as command.

ExpressionMeaning
* * * * * commandevery minute
*/5 * * * * commandevery 5 minutes
0 * * * * commandat minute 0 of every hour (hourly)
0 9 * * * commandevery day at 9:00
30 2 * * * commandevery day at 2:30 a.m. (good for backups)
0 9 * * 1 commandevery Monday at 9:00
0 9 * * 1-5 commandweekdays (Mon-Fri) at 9:00
0 0 1 * * commandat 0:00 on the 1st of every month
0 0 1 1 * commandat 0:00 on January 1 every year

The point is that the further left the field, the finer the unit. For "hourly," fix only the minute and leave the rest as *; for "daily," fix the minute and hour and leave the rest as *; for "weekly," also specify the weekday. By widening the fixed fields to the right, you approach the cycle you want.

It is hard to judge whether such expressions are correct in your head alone. With the Cron Generator you can produce a correct cron expression just by choosing the cycle on screen, and you can also enter an expression to confirm "when it will run next." Because you can refine the setting through trial and error, it helps prevent writing mistakes. Everything runs in your browser, so what you enter is never sent anywhere.

Pitfalls to Watch For

Cron is powerful, but there are several traps that are easy to stumble into. Finally, here are the main points to keep in mind.

  1. Environment variables (especially PATH) are limited: cron runs in a minimal environment different from your login shell, so a command may not be found. It is safer to write an absolute path such as /usr/bin/python3, or to set PATH inside your script.
  2. Specifying day and weekday together is an OR condition: for example, 0 0 1 * 1 runs if either "the 1st of the month" or "every Monday" matches. This part easily behaves differently from what you intend.
  3. Check the time zone: the run time shifts depending on the server's clock setting (UTC or local time). If it differs from your expectation, suspect the time zone first.
  4. Output and errors are easily lost: standard output and errors pile up in mail or get discarded if left alone. Append them to a log with something like >> /path/to/log 2>&1 so you can investigate later.
  5. Beware of overlapping runs: if the next run starts before the previous one finishes, you get multiple instances. For long-running tasks, use a lock file or similar to prevent overlap.

Cron has only five fields and four symbols to learn, yet a remarkably wide range of uses. Start by assembling your target cycle in the Cron Generator, check the generated expression and the next run time, and gradually shape it to fit your own operations.

This article is general information, and cron's behavior differs in detail depending on the OS, distribution, and cron implementation you use. For exact specifications, check the official documentation (such as the man pages) for your environment.

FAQ

What is cron (crontab)?

Cron is a scheduler for recurring execution built into Linux and macOS. A background program checks the registered schedule every minute and automatically runs any command whose time matches. The configuration file that lists the schedules is called a crontab, which you edit with crontab -e. It is used for recurring work such as backups and aggregation.

What do the five cron fields represent?

From left to right they are minute (0-59), hour (0-23), day of month (1-31), month (1-12), and day of week (0-7, where 0 and 7 are Sunday). For example, 30 9 * * * means minute=30 and hour=9 with the rest unspecified, so it runs every day at 9:30.

How do I write "daily," "hourly," and "weekly"?

Hourly is 0 * * * * (minute 0 of every hour), daily is 0 9 * * * (every day at 9:00), and weekly is 0 9 * * 1 (every Monday at 9:00). Put a number in the field you want to fix and leave the fields to its right as *. For every 5 minutes, use a slash to set the interval, as in */5 * * * *.

How do I use the symbols * / , -?

* means all values (every time), / means an interval (*/5 is every 5 minutes), , lists multiple values (0,30 is minute 0 and 30), and - is a range (1-5 is Mon-Fri). They can be combined; for example, 0-30/10 means every 10 minutes from minute 0 to 30.

Is what I enter into the cron generator sent anywhere?

WAZA TOOLS' Cron Generator runs entirely in your browser. The schedule and command you enter are never sent to or stored on a server, so you can use it with confidence.