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
| Position | Field | Values |
|---|---|---|
| 1 | Minute | 0-59 |
| 2 | Hour | 0-23 |
| 3 | Day of month | 1-31 |
| 4 | Month | 1-12 |
| 5 | Day of week | 0-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."
- Minute: 30 →
30 - Hour: 9 →
9 - Day of month: doesn't matter →
* - Month: every month →
* - 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
| Expression | Meaning |
|---|---|
* * * * * | Every minute |
*/5 * * * * | Every 5 minutes |
0 * * * * | Every hour on the hour |
0 3 * * * | Every day at 03:00 |
30 9 * * 1-5 | Every weekday at 09:30 |
0 0 1 * * | At midnight on the first day of every month |
0 0 * * 0 | At 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
0 9-17 * * 1-5: Every hour on the hour during weekday working hours (09:00 to 17:00); 9 times a day.15,45 * * * *: At minutes 15 and 45 of every hour; half an hour apart but offset from the top of the hour.0 2 * * 6: Every Saturday at 02:00; suitable for a weekly backup or cleanup.
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
- The % character: In a command,
%counts as a newline. For a dated file name write\%F:0 2 * * * tar czf /yedek/site-$(date +\%F).tgz /var/www. - PATH is limited: Use full paths in commands (
/usr/bin/python3). - Output disappears: To debug, redirect with
>> file.log 2>&1. - Shortcuts: Many versions have forms such as
@rebootand@daily; not all are supported on every system.
Common mistakes
- Forgetting the time zone: The UTC example above.
- Expecting "and" in the day fields: It is actually "or".
- Not using absolute paths: The command runs in your own terminal but cannot be found under cron.
- Not redirecting output: You will not notice a failure.
- Running too often: Jobs that run every minute for no reason tire the server.
- 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
- crontab: The file that holds a user's scheduled jobs.
- Step: The increment given with
/; it starts from the beginning of the range. - UTC: Coordinated Universal Time; Turkish time is UTC+3.
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
- What Is a Unix Timestamp (Epoch Time)? Converting to and from Dates, the 2038 Problem – What is a Unix timestamp (epoch) and how do you convert seconds to a date? Manual math, Python, JavaScript and terminal code, milliseconds and 2038.
- How to Calculate Age From a Date of Birth: Age in Years, Months and Days – Work out your exact age in years, months and days, step by step. Month-end and leap-day edge cases, total days lived and common mistakes.
- How to Calculate Days and Business Days Between Two Dates: Step by Step – How many days and business days lie between two dates? End-day rule, the full-week shortcut, leap years and the Excel difference, with worked examples.
- What Is Semver? MAJOR.MINOR.PATCH Version Numbers and ^ ~ Ranges – What is semantic versioning (semver)? MAJOR.MINOR.PATCH bump rules, pre-release ordering, ^ and ~ ranges and which version gets installed, with examples.
- How to Add and Subtract Hours and Minutes: A Guide to Time Calculations – How to add and subtract hours and minutes: the base-60 system, decimal hours, plus shift, overtime and video length examples and common mistakes.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.