Cron Cheat Sheet
Crontab syntax reference: fields, special strings, ranges, and common schedules.
Cron runs commands at recurring times using a compact schedule expression. A user crontab normally contains five time fields followed by a command; system crontabs may include an additional user field.
Five-field layout
The fields are evaluated in this order: minute, hour, day of month, month, and day of week. Names and ranges can vary slightly between cron implementations, so check the local man page for portability-sensitive jobs.
| Field | Allowed values | Example |
|---|---|---|
| Minute | 0–59 | 15 |
| Hour | 0–23 | 9 |
| Day of month | 1–31 | 1 |
| Month | 1–12 or names | 1,6,12 |
| Day of week | 0–7 or names; Sunday is commonly 0 or 7 | 1–5 |
minute hour day-of-month month day-of-week command
15 9 * * 1-5 /usr/local/bin/report
Operators and special fields
Use * for every value, commas for a list, hyphens for a range, and slash for steps. L, W, and # are extensions supported by some cron implementations, not universal crontab syntax.
| Syntax | Meaning |
|---|---|
* | Every allowed value. |
1,15,30 | Specific values. |
1-5 | Inclusive range. |
*/5 | Every fifth value. |
1-59/2 | Odd values in the range. |
L | Last day or weekday position in some implementations. |
W | Nearest weekday in some implementations. |
MON#2 | Second Monday in some implementations. |
*/5 * * * * /usr/local/bin/health-check
0 0 1 * * /usr/local/bin/monthly-close
Special strings
Special strings make common schedules easier to read. Availability depends on the cron daemon; @reboot runs when the daemon starts rather than at a calendar time.
| String | Equivalent idea |
|---|---|
@yearly | Once a year. |
@monthly | Once a month. |
@weekly | Once a week. |
@daily | Once a day. |
@hourly | Once an hour. |
@reboot | Once after startup or daemon launch. |
@daily /usr/local/bin/backup
@reboot /usr/local/bin/start-worker
Common schedules
Cron uses the machine’s local timezone unless the daemon or configuration supplies a different timezone. Document the intended timezone for production jobs.
| Schedule | Meaning |
|---|---|
* * * * * | Every minute. |
*/5 * * * * | Every five minutes. |
0 * * * * | At the start of every hour. |
0 9 * * * | Every day at 09:00. |
0 0 * * 1-5 | Weekdays at midnight. |
30 18 * * 1-5 | Weekdays at 18:30. |
0 0 1 * * | First day of every month at midnight. |
Crontab commands
Edit the current user’s crontab without opening the system-wide scheduler configuration. Keep backups of important entries before replacing a complete crontab from standard input.
crontab -e
crontab -l
crontab -r
crontab -l > crontab.backup
crontab crontab.backup
Environment and reliability
Cron starts with a sparse environment. Use absolute executable paths, set PATH explicitly when needed, redirect output, and use a lock when overlapping runs would be unsafe.
SHELL=/bin/sh
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=ops@example.com
0 2 * * * /usr/local/bin/backup >> /var/log/backup.log 2>&1
In many crontab implementations, % in the command is special and must be escaped as \% when passed to the command.
References
man 5 crontab- Cron