Master cron expressions with this comprehensive guide covering syntax, special characters, common patterns, and advanced techniques. From basic scheduling to complex automation scenarios.
🚀 Quick Start
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of week (0 - 7) (Sunday is both 0 and 7)
# │ │ │ │ │
# * * * * * command-to-execute0 9 * * 1-5 /path/to/script.shRuns at 9 AM every weekday📋 Field-by-Field Reference
Each cron expression consists of five time and date fields. Understanding each field's range and syntax is crucial for creating accurate schedules.
Minute
Range: 0-59*Every minute
0At minute 0 (start of hour)
*/5Every 5 minutes
15,45At minutes 15 and 45
10-20Minutes 10 through 20
Hour
Range: 0-23*Every hour
0At midnight (12:00 AM)
12At noon (12:00 PM)
9-17Business hours (9 AM to 5 PM)
*/6Every 6 hours
Day of Month
Range: 1-31*Every day
1First day of month
1515th day of month
*/2Every 2nd day
1,151st and 15th
Month
Range: 1-12*Every month
1January only
6-8June through August
*/3Every 3 months
12December only
Day of Week
Range: 0-7*Every day
0Sunday (also 7)
1-5Monday through Friday
6,0Saturday and Sunday
1Monday only
⭐ Special Characters Reference
These special characters enable complex scheduling patterns and advanced time specifications.
Asterisk (Wildcard)
Matches any value in the field
* * * * * = every minute0 * * * * = every hour at minute 0Comma (List)
Separates multiple values
0 9,17 * * * = at 9 AM and 5 PM0 0 1,15 * * = 1st and 15th of monthHyphen (Range)
Defines a range of values
0 9-17 * * * = every hour from 9 AM to 5 PM0 0 * * 1-5 = weekdays at midnightSlash (Step)
Specifies step values or intervals
*/15 * * * * = every 15 minutes0 */2 * * * = every 2 hoursQuestion Mark
No specific value (some implementations)
0 0 ? * MON = every Monday (day of month ignored)Last
Last occurrence (some implementations)
0 0 L * * = last day of month0 0 * * 5L = last Friday of monthNth occurrence
Nth occurrence of weekday (some implementations)
0 0 * * MON#2 = second Monday of month⚙️ Common Cron Job Macros
Modern cron implementations support convenient macros that replace common timing patterns.
| Macro | Equivalent | Description | Common Use Cases |
|---|---|---|---|
@reboot | N/A | Run once at system startup | Initialize services, mount drives |
@yearly / @annually | 0 0 1 1 * | Run once per year on January 1st | Annual reports, license renewals |
@monthly | 0 0 1 * * | Run once per month on the 1st | Monthly billing, reports |
@weekly | 0 0 * * 0 | Run once per week on Sunday | Weekly backups, maintenance |
@daily / @midnight | 0 0 * * * | Run once per day at midnight | Daily cleanup, log rotation |
@hourly | 0 * * * * | Run once per hour | Cache clearing, monitoring checks |
🗓️ Common Scheduling Patterns
These frequently-used patterns cover most scheduling scenarios you'll encounter.
0 0 * * *Daily at midnight
Daily maintenance tasks, backups, reports
0 */6 * * *Every 6 hours
Regular system checks, data synchronization
*/15 * * * *Every 15 minutes
Frequent monitoring, API health checks
0 9 * * 1-5Weekdays at 9 AM
Business hour tasks, sending daily reports
0 2 * * 0Sundays at 2 AM
Weekly maintenance, major backups
0 0 1 * *First day of every month
Monthly reports, billing processes
0 0 1 1 *January 1st at midnight
Annual tasks, yearly archiving
*/5 9-17 * * 1-5Every 5 minutes during business hours
Active monitoring during work hours
💡 Advanced Cron Job Examples
Complex scheduling scenarios that demonstrate advanced cron syntax capabilities.
Complex Business Logic
0 8,12,17 * * 1-5Run at 8 AM, noon, and 5 PM on weekdays
Perfect for sending status updates at key business times
Quarterly Reports
0 9 1 1,4,7,10 *9 AM on the first day of each quarter
Automatically generate quarterly business reports
Bi-weekly Tasks
0 0 * * 0/2Every other Sunday at midnight
For tasks that need to run every two weeks
Working Hours Monitoring
*/10 8-18 * * 1-5Every 10 minutes from 8 AM to 6 PM, weekdays only
Intensive monitoring during business operations
⚠️ Important Notes & Best Practices
Time Zone Considerations:
- • Cron uses the system's local time zone
- • Consider daylight saving time changes
- • Use UTC for consistency across servers
- • Document time zones in your cron jobs
Syntax Variations:
- • Some systems support 6-field format (with seconds)
- • Not all special characters work everywhere
- • Test expressions on your specific system
- • Check your cron implementation's documentation
🛠️ Validation & Testing
Before Adding to Crontab:
- 1. Test the command manually
- 2. Verify file paths are absolute
- 3. Check required permissions
- 4. Add proper logging and error handling
- 5. Use our cron generator to validate timing
Debugging Tips:
- • Check cron daemon logs (/var/log/cron)
- • Redirect output: command >> /var/log/job.log 2>&1
- • Verify environment variables
- • Test with simplified versions first
- • Use mail output to catch errors
Ready to Create Your Cron Expression?
Use our interactive cron generator to build and validate expressions based on this syntax guide.
Bookmark this cheatsheet for quick reference when creating cron jobs.
Need more help? Check out our troubleshooting guideor explore detailed tutorials.