Understanding Cron Syntax: A Complete Guide

A detailed breakdown of the cron syntax, including special characters, keywords, and practical examples.

10 min read
Complete Cron Syntax Cheatsheet & Reference Guide

Master cron expressions with this comprehensive guide covering syntax, special characters, common patterns, and advanced techniques. From basic scheduling to complex automation scenarios.

🕒 5 min read📋 Complete reference💡 50+ examples

🚀 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-execute
Example:0 9 * * 1-5 /path/to/script.shRuns at 9 AM every weekday
Test First:Always test commands manually before scheduling

📋 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

0

At minute 0 (start of hour)

*/5

Every 5 minutes

15,45

At minutes 15 and 45

10-20

Minutes 10 through 20

Hour

Range: 0-23
*

Every hour

0

At midnight (12:00 AM)

12

At noon (12:00 PM)

9-17

Business hours (9 AM to 5 PM)

*/6

Every 6 hours

Day of Month

Range: 1-31
*

Every day

1

First day of month

15

15th day of month

*/2

Every 2nd day

1,15

1st and 15th

Month

Range: 1-12
*

Every month

1

January only

6-8

June through August

*/3

Every 3 months

12

December only

Day of Week

Range: 0-7
*

Every day

0

Sunday (also 7)

1-5

Monday through Friday

6,0

Saturday and Sunday

1

Monday only

⭐ Special Characters Reference

These special characters enable complex scheduling patterns and advanced time specifications.

*

Asterisk (Wildcard)

Matches any value in the field

* * * * * = every minute
0 * * * * = every hour at minute 0
,

Comma (List)

Separates multiple values

0 9,17 * * * = at 9 AM and 5 PM
0 0 1,15 * * = 1st and 15th of month
-

Hyphen (Range)

Defines a range of values

0 9-17 * * * = every hour from 9 AM to 5 PM
0 0 * * 1-5 = weekdays at midnight
/

Slash (Step)

Specifies step values or intervals

*/15 * * * * = every 15 minutes
0 */2 * * * = every 2 hours
?

Question Mark

No specific value (some implementations)

0 0 ? * MON = every Monday (day of month ignored)
L

Last

Last occurrence (some implementations)

0 0 L * * = last day of month
0 0 * * 5L = last Friday of month
#

Nth 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.

MacroEquivalentDescriptionCommon Use Cases
@rebootN/ARun once at system startupInitialize services, mount drives
@yearly / @annually0 0 1 1 *Run once per year on January 1stAnnual reports, license renewals
@monthly0 0 1 * *Run once per month on the 1stMonthly billing, reports
@weekly0 0 * * 0Run once per week on SundayWeekly backups, maintenance
@daily / @midnight0 0 * * *Run once per day at midnightDaily cleanup, log rotation
@hourly0 * * * *Run once per hourCache 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-5

Weekdays at 9 AM

Business hour tasks, sending daily reports

0 2 * * 0

Sundays 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-5

Every 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-5

Run 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/2

Every other Sunday at midnight

For tasks that need to run every two weeks

Working Hours Monitoring

*/10 8-18 * * 1-5

Every 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. 1. Test the command manually
  2. 2. Verify file paths are absolute
  3. 3. Check required permissions
  4. 4. Add proper logging and error handling
  5. 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.

Ready to Create Your Cron Job?

Now that you understand the concepts, try our cron expression generator to create your own cron jobs!

Try Cron Generator