Cron Expression Guide: 5-Field Syntax + Real-World Examples

Almost every server-side scheduled task — log rotation, database backups, email reminders, daily reports — runs on cron. But the syntax can be cryptic: a string of * * * * * leaves many developers staring blankly.

✍️ Author:DevToolbox Team📅 Updated:2026-06-24📎 References:RFC Standards

📌 Key Takeaways

  • Cron Expression Guide: 5-Field Syntax + Real-World is widely used by developers
  • Based on RFC standards and real-world experience
  • Free online tools, runs locally, no data upload
  • FAQ section at the bottom answers common questions
✍️ Author:DevToolbox Team📅 Updated:2026-06-24📎 References:RFC Standards

📌 Key Takeaways

  • Cron Expression Guide: 5-Field Syntax + Real-World is widely used by developers
  • Based on RFC standards and real-world experience
  • Free online tools, runs locally, no data upload
  • FAQ section at the bottom answers common questions

This guide explains the 5-field cron syntax, special characters, the 6-field variant (with seconds), and 10 real-world examples. Use our online Cron Parser to verify your expressions instantly.

1. What a Cron Expression Looks Like

Standard cron has 5 fields (some systems support 6 with seconds), left to right: minute, hour, day-of-month, month, day-of-week. Each field separated by a space.

* * * * *
│ │ │ │ │
│ │ │ │ └─ Day of week (0-6, 0=Sunday)
│ │ │ └─── Month (1-12)
│ │ └───── Day of month (1-31)
│ └─────── Hour (0-23)
└───────── Minute (0-59)

Classic example: 0 2 * * * means every day at 2:00 AM. First field 0 = minute 0, second field 2 = hour 2, the three * = any value.

2. 9 Essential Special Characters

Char Meaning Example
*Any value (every)* = every minute
,List separator1,15 = 1 and 15
-Range9-17 = 9 through 17
/Step (every N)*/10 = every 10 minutes
?No specific value0 0 ? * 1 = every Monday
LLast dayL = last day of month
WNearest weekday15W = nearest weekday to the 15th
#Nth occurrence5#2 = 2nd Friday
@Preset alias@daily = 0 0 * * *

3. 6-Field / 7-Field Cron (Seconds & Year)

Standard Unix cron is 5 fields, but Quartz (Java), Spring, AWS EventBridge use 6 or 7 fields — adding seconds at the front and optionally year at the end:

0 0 2 * * *      (6-field: sec min hour day month weekday)
0 0 2 * * * 2026 (7-field: add year)

Always check your target system — "every day at 2 AM" is 0 2 * * * in Linux crontab but 0 0 2 * * ? in Spring @Scheduled.

4. 10 Real-World Examples

Ops / Backup

  1. Health check every 5 min: */5 * * * *
  2. Daily backup at 2 AM: 0 2 * * *
  3. Log cleanup every Sunday 3 AM: 0 3 * * 0
  4. Monthly report on the 1st: 0 1 1 * *
  5. Weekday daily report at 11 PM: 0 23 * * 1-5

Business / Data

  1. Hourly data sync: 0 * * * *
  2. Order pull every 15 min: */15 * * * *
  3. Push every 30 min, 9 AM–6 PM: */30 9-18 * * *
  4. Mon/Wed/Fri reminder at 8:30 AM: 30 8 * * 1,3,5
  5. Last day of month cleanup at 23:59: 59 23 L * *

5. 3 Common Pitfalls

Pitfall 1: Specifying both day-of-month and day-of-week. Cron treats them as OR — if either matches, the job fires. Use ? as a no-op in Quartz.

Pitfall 2: Forgetting timezone. Server default is often UTC. 0 9 * * * on a UTC server fires at 9 AM UTC, not 9 AM local time. Always check timedatectl.

Pitfall 3: Missing environment variables. Cron runs with a minimal environment — no ~/.bashrc. Use absolute paths or source /etc/profile at the top of your script.

6. Verify with Our Online Tool

The worst feeling: writing a cron expression, deploying it, and waiting a day to see if it fired. Use the DevToolbox Cron Parser:

7. Summary

Cron isn't hard — it's just symbols. Memorize * , - / ? L and follow the three-step workflow: pick a template → verify with the parser → write to crontab. For complex scheduling (dynamic cron, cross-timezone coordination), reach for Airflow / Temporal.

Related tools: Cron Parser · UUID Generator · Base64 Encoder

🔗 Share: 𝕏 📘 ✈️ 💬

FAQ: Common Questions

Q: Cron 表达式是什么?

Cron 是 Unix 系统的定时任务调度器,表达式 5-6 个字段表示时间(分 时 日 月 周)。例如 `0 9 * * 1-5` = 工作日早 9 点。

Q: Cron 表达式怎么写?

5 个字段:分(0-59) 时(0-23) 日(1-31) 月(1-12) 周(0-6)。特殊字符:* 任意、, 列表、- 范围、/ 步长。例:*/15 * * * * = 每 15 分钟。

Q: Cron 表达式调试工具有哪些?

crontab.guru(Cron 表达式翻译器)、DevToolbox Cron Parser(可视化解析)。复杂调度建议用 systemd timer 替代 Cron。

🧰
Add to Home Screen
Works offline, launches instantly