Cron Expression Cheat Sheet & Examples
发布时间:2026-09-17 | 浏览:2
Cron expressions are the backbone of scheduled tasks in Unix, Linux, macOS, CI/CD pipelines, cloud functions, and container orchestration. They look cryptic at first — 0 */6 * * 1-5 — but once you understand the five (or six) fields, you can schedule anything.
This cheat sheet covers the standard 5-field cron syntax, extended 6-field syntax (with seconds), every special character, and dozens of real-world examples you can copy-paste into your crontab, GitHub Actions, or Kubernetes CronJob.
Cron Syntax: The 5 Fields
A standard cron expression has five fields separated by spaces:
Each field can contain a single value, a range, a list, a step, or a wildcard. The expression fires when all five fields match the current time.
Special Characters Explained
Note: L , W , # , and ? are extensions used in Quartz (Java), Spring, and some cloud platforms. Standard Unix crontab only supports * , , , - , and / .
Common Cron Patterns
Here are the patterns you'll use most often, ready to copy-paste.
Every X Minutes
Daily Schedules
Weekly Schedules
Monthly and Yearly Schedules
Extended 6-Field Syntax (Seconds)
Some systems (Quartz, Spring, AWS EventBridge) support a sixth field for seconds:
Warning: Standard Unix crontab does NOT support seconds. If you need sub-minute scheduling on Linux, use a workaround like running a script every minute that internally sleeps.
Cron in Different Environments
Linux / macOS Crontab
Edit your crontab with crontab -e :
Key crontab tips:
Always redirect output ( > /dev/null 2>&1 ) or cron will email you on every run.
Use full paths for commands — cron's PATH is minimal.
Set MAILTO="" at the top to disable email notifications entirely.
Use crontab -l to list current jobs, crontab -r to remove all.
GitHub Actions uses UTC only. Runs may be delayed by up to 15 minutes during peak load. Minimum interval is 5 minutes, but GitHub may throttle more frequent schedules.
Kubernetes CronJob
AWS CloudWatch / EventBridge
AWS uses a slightly different syntax with 6 fields (year is optional):
Note that AWS uses ? for "no specific value" in either day-of-month or day-of-week (you must use ? in exactly one of them).
Debugging Cron Expressions
The most common cron bugs:
Timezone confusion. Crontab runs in the system's local timezone. GitHub Actions and AWS use UTC. Always document which timezone your cron uses.
Timezone confusion. Crontab runs in the system's local timezone. GitHub Actions and AWS use UTC. Always document which timezone your cron uses.
Day-of-month AND day-of-week. In standard cron, if both are set (not * ), the job runs when either matches — not both. This catches people off guard. 0 0 15 * 5 runs on the 15th AND every Friday.
Day-of-month AND day-of-week. In standard cron, if both are set (not * ), the job runs when either matches — not both. This catches people off guard. 0 0 15 * 5 runs on the 15th AND every Friday.
February 30th. 0 0 30 2 * will never fire. Cron silently skips impossible dates.
February 30th. 0 0 30 2 * will never fire. Cron silently skips impossible dates.
Step misunderstanding. */7 * * * * does NOT run every 7 minutes starting from the last run. It runs at minutes 0, 7, 14, 21, 28, 35, 42, 49, 56. The step divides the range, not the interval from last execution.
Step misunderstanding. */7 * * * * does NOT run every 7 minutes starting from the last run. It runs at minutes 0, 7, 14, 21, 28, 35, 42, 49, 56. The step divides the range, not the interval from last execution.
Overlapping runs. If a job takes 10 minutes but runs every 5, you'll get overlapping executions. Use a lock file or concurrencyPolicy: Forbid in Kubernetes.
Overlapping runs. If a job takes 10 minutes but runs every 5, you'll get overlapping executions. Use a lock file or concurrencyPolicy: Forbid in Kubernetes.
Advanced Patterns
First and Last Day of Month
Standard cron doesn't have "last day of month" — but you can script around it:
In Quartz/Spring, use the L modifier: 0 0 0 L * ?
Every Other Week
Cron can't express "every other week" natively. Workaround: run weekly and check the week number inside your script:
Random Delay (Jitter)
To avoid thundering-herd problems when many servers run the same cron:
Cron vs. Alternatives
Build and Test Your Cron Expressions
The fastest way to get a cron expression right is to build it visually. Try DevToolkit's Cron Expression Builder — select your schedule with dropdowns, see the next 5 execution times instantly, and copy the expression. No guessing, no syntax errors.
It supports both standard 5-field and extended 6-field syntax, with human-readable descriptions of what the expression does. Perfect for validating expressions before deploying to production.
Quick Reference Card
Cron expressions are deceptively simple — five fields, a handful of special characters, infinite scheduling power. The key is understanding how fields combine and knowing the quirks of your specific platform (Unix crontab vs. Quartz vs. AWS).
Bookmark this cheat sheet for quick reference. And when you need to build or validate a cron expression, use DevToolkit's visual Cron Expression Builder to get it right the first time.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.