Cron Expression Explained: Schedule Tasks Like a Pro
Master cron syntax from basic patterns to advanced scheduling. Parse, debug, and create cron expressions for Linux, Kubernetes, and CI/CD.
What Is a Cron Expression?
A cron expression is a compact string that defines a schedule for recurring tasks. Originating from the Unix cron daemon, the format has become the universal standard for scheduling — used in Linux crontabs, Kubernetes CronJobs, CI/CD pipelines, and cloud functions.
A standard cron expression has five fields: minute hour day month weekday. Our Cron Parser breaks down any cron expression into plain English and shows upcoming execution times.
Cron Expression Syntax
┌───────────── minute (0–59)
│ ┌───────────── hour (0–23)
│ │ ┌───────────── day of month (1–31)
│ │ │ ┌───────────── month (1–12)
│ │ │ │ ┌───────────── day of week (0–7, 0 and 7 = Sunday)
│ │ │ │ │
* * * * *
Special Characters
*— any value (every minute, every hour, etc.),— list of values:1,3,5-— range:1-5(Monday through Friday)/— step:*/15(every 15 units)?— no specific value (used in some implementations for day-of-month or day-of-week)
Common Cron Patterns
Here are the expressions you'll use most often:
*/5 * * * * Every 5 minutes
0 * * * * Every hour (at minute 0)
0 9 * * * Every day at 9:00 AM
0 9 * * 1-5 Weekdays at 9:00 AM
0 0 1 * * First day of every month at midnight
0 0 * * 0 Every Sunday at midnight
30 6,18 * * * Twice daily at 6:30 AM and 6:30 PM
0 */2 * * * Every 2 hours
Cron in Practice
Linux Crontab
Edit your user's crontab with crontab -e and add one expression per line:
# Run backup script every day at 3:00 AM
0 3 * * * /home/user/scripts/backup.sh >> /var/log/backup.log 2>&1
# Clean temp files every Sunday at 2:00 AM
0 2 * * 0 find /tmp -type f -mtime +7 -delete
# Send health check every 5 minutes
*/5 * * * * curl -sf https://api.example.com/health || echo "Down!" | mail -s "Alert" [email protected]
Kubernetes CronJob
apiVersion: batch/v1
kind: CronJob
metadata:
name: data-sync
spec:
schedule: "0 */6 * * *" # Every 6 hours
jobTemplate:
spec:
template:
spec:
containers:
- name: sync
image: data-sync:latest
restartPolicy: OnFailure
GitHub Actions
# .github/workflows/cleanup.yml
name: Cleanup
on:
schedule:
- cron: '0 0 * * 0' # Weekly on Sunday
jobs:
clean:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./scripts/cleanup.sh
Extended Cron: 6 and 7 Field Formats
Some systems extend cron to 6 or 7 fields, adding seconds and/or year:
Standard (5): 0 9 * * *
With seconds: 0 0 9 * * * (Spring, Quartz)
With year: 0 0 9 * * * 2026 (Quartz scheduler)
Our Cron Parser handles both standard and extended formats, showing clear descriptions regardless of the variant.
Timezone Considerations
Standard cron runs in the system's local timezone. For cloud services, always verify the timezone context:
- Linux crontab: Uses
TZenvironment variable or system timezone - AWS CloudWatch Events: Always UTC
- Google Cloud Scheduler: Configurable per job
- Kubernetes: Uses the kube-controller-manager's timezone
Debugging Cron Expressions
The most common cron mistakes:
- Wrong day-of-week numbering: Some systems use 0=Sunday, others 1=Monday. Check your platform.
- Missing environment: Cron runs with minimal PATH. Always use absolute paths in commands.
- Silent failures: Redirect output to a log file or you'll never know the job ran (or failed).
# Bad: cron can't find the command
0 9 * * * my-script.sh
# Good: absolute paths and logging
0 9 * * * /usr/local/bin/my-script.sh >> /var/log/my-script.log 2>&1
FAQ
How do I run a cron job every 30 seconds?
You can't — cron's minimum granularity is one minute. For sub-minute scheduling, use a loop in your script, systemd timers, or a dedicated scheduler.
What's the difference between 0 and 7 for Sunday?
Both represent Sunday in standard cron. Use whichever you prefer; 0 is more common.
Can I test a cron expression without waiting?
Yes! Use our Cron Parser to see the next N execution times instantly. No waiting required.
Why didn't my cron job run?
Check: correct file permissions on the script, absolute paths in commands, sufficient disk space, and that the cron daemon is running (systemctl status cron).
Conclusion
Cron expressions are the lingua franca of task scheduling. Master the five-field syntax, learn the common patterns, and you'll handle everything from backup scripts to CI/CD pipelines. Use our Cron Parser to visualize and validate any cron expression with human-readable descriptions and upcoming run times.
Ready to try it?
Open Tool →