All cheat sheets

Cron Cheat Sheet

Crontab syntax reference: fields, special strings, ranges, and common schedules.

CLI & Shell
cron
scheduling
linux

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.

Table
FieldAllowed valuesExample
Minute0–5915
Hour0–239
Day of month1–311
Month1–12 or names1,6,12
Day of week0–7 or names; Sunday is commonly 0 or 71–5
cron
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.

Table
SyntaxMeaning
*Every allowed value.
1,15,30Specific values.
1-5Inclusive range.
*/5Every fifth value.
1-59/2Odd values in the range.
LLast day or weekday position in some implementations.
WNearest weekday in some implementations.
MON#2Second Monday in some implementations.
cron
*/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.

Table
StringEquivalent idea
@yearlyOnce a year.
@monthlyOnce a month.
@weeklyOnce a week.
@dailyOnce a day.
@hourlyOnce an hour.
@rebootOnce after startup or daemon launch.
cron
@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.

Table
ScheduleMeaning
* * * * *Every minute.
*/5 * * * *Every five minutes.
0 * * * *At the start of every hour.
0 9 * * *Every day at 09:00.
0 0 * * 1-5Weekdays at midnight.
30 18 * * 1-5Weekdays 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.

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

cron
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

Related tools