What is Cron? Complete Guide with Examples
Cron is a time-based job scheduler in Unix-like operating systems that executes commands or scripts at specified times, dates, or intervals. Cron expressions are strings that define the schedule using five fields: minute, hour, day of month, month, and day of week. For example, '0 9 * * 1' means 'every Monday at 9:00 AM'. Cron is fundamental to system administration, DevOps, and backend development for automating recurring tasks.
Use our free Cron Expression Parser to experiment with cron expressions.
How Does Cron Expressions Work?
The cron daemon reads crontab files containing schedule entries and command pairs. Each entry specifies when to run (the cron expression) and what to run (the command). The daemon checks every minute if any scheduled time matches the current time. Cron expressions use five space-separated fields: minute (0-59), hour (0-23), day of month (1-31), month (1-12), day of week (0-7). Special characters include * (any), , (list), - (range), / (step), and some implementations support @yearly, @monthly, @weekly, @daily shorthands.
Key Features
- Five-field syntax covering minute, hour, day-of-month, month, and day-of-week
- Special characters: * (any value), , (value list), - (range), / (step/interval)
- Shorthand macros like @daily, @weekly, @monthly, @yearly for common schedules
- Human-readable description generation from cron expressions
- Next-run calculation showing upcoming execution times for verification
Common Use Cases
Database Backups
System administrators schedule nightly database backups using cron: '0 2 * * *' runs the backup script at 2:00 AM every day, ensuring data is regularly protected.
Report Generation
Business applications generate weekly reports on schedule: '0 8 * * 1' produces and emails the report every Monday at 8:00 AM.
Cache Cleanup
DevOps teams schedule periodic cleanup of temporary files, expired cache entries, and old logs to prevent disk space issues: '0 */6 * * *' runs every 6 hours.