What is a Cron Job and How Do Crontab Schedules Work?
A Cron Job is an automated background task scheduled to run periodically on Unix-like operating systems (Linux, macOS, BSD) via the system daemon cron. First introduced by Brian Kernighan in Version 7 Unix in 1979, cron enables system administrators, DevOps engineers, and web developers to schedule recurring operations such as database backups, SSL certificate renewals, cache warming, email queues, and log rotations.
Schedules are configured in tables called crontabs using a compact, space-delimited 5-field syntax.
The 5 Fields of a Crontab Expression Explained
A standard crontab entry contains five fields separated by whitespace:
* * * * * <command-to-execute>
| Position | Field Name | Allowed Values | Special Characters Allowed |
|---|---|---|---|
| 1 | Minute | 0 โ 59 | * , - / |
| 2 | Hour | 0 โ 23 (24-hour time) | * , - / |
| 3 | Day of Month | 1 โ 31 | * , - / L W |
| 4 | Month | 1 โ 12 or JAN โ DEC | * , - / |
| 5 | Day of Week | 0 โ 6 (0 = Sunday) or SUN โ SAT | * , - / L # |
Cron Operators & Special Characters Guide
- Asterisk (
*): Wildcard representing "every" possible value within the field (e.g.*in the hour field means "every hour"). - Comma (
,): Specifies a discrete list of multiple values (e.g.1,15,30in the minute field runs at minute 1, 15, and 30). - Hyphen (
-): Defines an inclusive range of values (e.g.1-5in the day-of-week field runs Monday through Friday). - Slash (
/): Specifies a step interval (e.g.*/20in minutes means "every 20 minutes",0-23/2in hours means "every 2 hours").
Crontab Real-World Schedule Cheat Sheet
| Cron Schedule | Description & Typical Usage |
|---|---|
| * * * * * | Run once every single minute (e.g. high-frequency message queue processing). |
| */5 * * * * | Run every 5 minutes (e.g. uptime health checks, ping monitors). |
| 0 * * * * | Run at the start of every hour (e.g. hourly metric aggregation). |
| 0 0 * * * | Run daily at midnight 00:00 (e.g. daily database backup, log archiving). |
| 0 9 * * 1-5 | Run at 9:00 AM every weekday (Monday through Friday) (e.g. daily business summaries). |
| 0 0 1 1 * | Run at midnight on January 1st (annual financial year-end accounting reset). |
Frequently Asked Questions (FAQ)
How do I edit my crontab schedule on Linux or macOS?
Open your terminal and run crontab -e to edit your active user crontab file in your default editor (nano/vim). To list existing scheduled jobs without editing, run crontab -l.
What timezone does cron use when executing jobs?
The system cron daemon evaluates schedules against the server's local system timezone. To avoid daylight saving time bugs or confusion across distributed servers, best practice is to configure production servers to UTC (timedatectl set-timezone UTC).