TR

Home / Guides / How to Write a Cron Expression: Crontab Scheduling Guide with Examples and Common Traps

How to Write a Cron Expression: Crontab Scheduling Guide with Examples and Common Traps

Updated: November 6, 2026 · AracMerkezi

▶ Open Cron Expression Explainer

Cron is the scheduler on Linux and Unix systems that runs commands automatically at set times. Jobs such as backups, sending reports, cleanup scripts and regular data pulls are planned with cron. A schedule consists of five fields separated by spaces, followed by the command to run. This guide keeps the field table short and focuses on the places that need attention: how to build an expression step by step, the unexpected behavior of the step (/) character, the "or" rule in the day fields, the time zone, and the details that silently break a crontab line. We calculated the run times in the examples with a small scheduler we wrote ourselves; we did not run crontab on a real server, so be sure to test on your own system.

The five fields

PositionFieldValues
1Minute0-59
2Hour0-23
3Day of month1-31
4Month1-12
5Day of week0-7 (0 and 7 are Sunday)

Special characters: * every value, , list (1,15), - range (1-5), / step (*/10 every 10 units).

Building an expression step by step

Start from a plain-English sentence and fill the fields from left to right. Goal: "Run the report script every weekday at 09:30."

  1. Minute: 30 → 30
  2. Hour: 9 → 9
  3. Day of month: doesn't matter → *
  4. Month: every month → *
  5. Day of week: Monday to Friday → 1-5

Result: 30 9 * * 1-5. The full line with the command: 30 9 * * 1-5 /usr/bin/python3 /home/ali/rapor.py >> /home/ali/rapor.log 2>&1. After 10:07 on Thursday, November 5, 2026, the next runs of the expression are Friday, November 6 at 09:30, then Monday, November 9 at 09:30; the weekend is skipped.

Examples

ExpressionMeaning
* * * * *Every minute
*/5 * * * *Every 5 minutes
0 * * * *Every hour on the hour
0 3 * * *Every day at 03:00
30 9 * * 1-5Every weekday at 09:30
0 0 1 * *At midnight on the first day of every month
0 0 * * 0At midnight every Sunday

*/5 * * * * runs 24 × 60 / 5 = 288 times a day, which is 8,640 runs in 30 days. Choose a less frequent schedule if you do not really need it.

More patterns

After writing an expression, also ask "when does this not run?" The expression 0 9-17 * * 1-5 does not run at 17:30, because the minute field is 0; so the last run is at 17:00. Boundary questions like this catch most mistakes while you are still writing.

Trap 1: */7 does not give equal intervals

*/7 reads like "every 7 minutes" but really means "start at 0, advance in steps of 7, do not go past 59": 0, 7, 14, 21, 28, 35, 42, 49, 56. At the end of the hour, the run after 56 is at minute 0 of the next hour; the gap drops to 4 minutes. The same applies to hours: 0 */5 * * * runs at 0, 5, 10, 15 and 20, and the run after 20 is 00:00 the next day (4 hours later). Values that divide 60 or 24 evenly (5, 10, 15, 30; 2, 3, 4, 6, 12) do not have this problem.

Trap 2: Day of month and day of week together

If neither is *, in most cron versions the rule is not "and" but "or"; it runs when either condition matches. 0 0 13 * 5 does not mean "when the 13th is a Friday" but "on every 13th and every Friday". In December 2026 this expression runs on the 4th, 11th, 13th, 18th and 25th (5 times). If you really want "Friday the 13th," do not write it as an expression alone; check the date inside the script. Also, 0 0 31 * * runs only in months with 31 days (in 2026: 1, 3, 5, 7, 8, 10, 12).

Trap 3: Time zone

Cron runs according to the server's time zone. If the server is on UTC and you want 06:00 Turkish time (UTC+3), the expression must be 0 3 * * *. The same expression falls at 06:00 in the morning in Turkey; a job thought of as a "3 a.m. backup" may in fact be running at 6 a.m. Check the server's time zone from the output of date.

Trap 4: Small details in a crontab line

Common mistakes

  1. Forgetting the time zone: The UTC example above.
  2. Expecting "and" in the day fields: It is actually "or".
  3. Not using absolute paths: The command runs in your own terminal but cannot be found under cron.
  4. Not redirecting output: You will not notice a failure.
  5. Running too often: Jobs that run every minute for no reason tire the server.
  6. Starting a new run before the previous one has finished: For long-running jobs consider a lock file or flock.

When is cron not suitable?

In cases that require exact-second precision, triggering when an event happens, or running a missed job later when the computer was off, cron alone is not enough; consider system timers or job-queue tools.

Mini glossary

Verifying the expression

To test when your expression will run, paste it into the Cron Expression Explainer; you will see the explanation and the next run times. If you work with timestamps, the Unix Timestamp Converter and the Unix timestamp guide are useful, and for the time between two dates the Date Difference Calculator can help.

Frequently asked questions

How many fields does a cron expression have?

In the standard form five: minute, hour, day of month, month and day of week.

How do you write every 5 minutes?

The expression `*/5 * * * *` runs every 5 minutes; 12 times an hour and 288 times a day.

Which time zone does cron use?

The server's time zone; if the server is on UTC it is 3 hours behind Turkish time (UTC+3), so you write 03:00 for 06:00 Turkish time.

Tools mentioned in this guide

More guides

This article is for general information only and is not legal, financial or medical advice. We are not an official institution.