← Til baka

Cron Expressions Explained: A Complete Guide with Examples

Β· 5 mΓ­n lestrartΓ­mi Β· Almennt

Whether you're scheduling backups, running data pipelines, or automating deployments, cron is the backbone of task scheduling on Unix systems. But the syntax can be cryptic if you haven't memorized it.

Cron Expression Format

A cron expression has 5 fields (some systems use 6 or 7):

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ minute (0-59)
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ hour (0-23)
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ day of month (1-31)
β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ month (1-12)
β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ day of week (0-7, both 0 and 7 = Sunday)
β”‚ β”‚ β”‚ β”‚ β”‚
* * * * *

Special Characters

CharacterMeaningExample
*Any value* * * * * = every minute
,List1,15 * * * * = at minute 1 and 15
-Range0 9-17 * * * = hourly, 9AM-5PM
/Step*/10 * * * * = every 10 minutes

20 Most Common Cron Schedules

Here are the cron expressions you'll use 90% of the time:

Basic Intervals

* * * * *        # Every minute
*/5 * * * *      # Every 5 minutes
*/15 * * * *     # Every 15 minutes
*/30 * * * *     # Every 30 minutes
0 * * * *        # Every hour (at minute 0)
0 */2 * * *      # Every 2 hours
0 */6 * * *      # Every 6 hours
0 */12 * * *     # Every 12 hours

Daily Schedules

0 0 * * *        # Daily at midnight
0 6 * * *        # Daily at 6:00 AM
0 9 * * *        # Daily at 9:00 AM
30 23 * * *      # Daily at 11:30 PM

Weekly & Monthly

0 9 * * 1-5      # Weekdays at 9:00 AM
0 0 * * 0        # Weekly on Sunday at midnight
0 0 * * 1        # Weekly on Monday at midnight
0 0 1 * *        # Monthly on the 1st at midnight
0 0 15 * *       # Monthly on the 15th at midnight
0 0 1 1 *        # Yearly on January 1st

Business Hours

*/5 9-17 * * 1-5  # Every 5 min during business hours
0 9,12,17 * * 1-5 # At 9AM, noon, and 5PM on weekdays

Build Your Schedule Visually

Instead of memorizing syntax, use our free Cron Expression Generator. It lets you:

Real-World Cron Examples

Database Backup (Daily at 2 AM)

0 2 * * * pg_dump mydb > /backups/db-$(date +\%Y\%m\%d).sql

Log Rotation (Weekly)

0 0 * * 0 find /var/log/app -name '*.log' -mtime +7 -delete

Health Check (Every 5 Minutes)

*/5 * * * * curl -sf https://api.example.com/health || alert.sh

Report Generation (Weekdays at 8 AM)

0 8 * * 1-5 python3 /scripts/daily-report.py

Common Mistakes

More Developer Tools

Build faster with our free developer tools: