CLI

Cron Cheatsheet

Quick reference for cron expression syntax, special strings, field values, and common scheduling patterns.

Cron Expression Format

┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12 or JAN-DEC)
│ │ │ │ ┌───────────── day of week (0-7 or SUN-SAT, 0 and 7 = Sunday)
│ │ │ │ │
* * * * *  command

Field Values

FieldAllowed ValuesSpecial Characters
Minute0-59* , - /
Hour0-23* , - /
Day of Month1-31* , - / ? L W
Month1-12 or JAN-DEC* , - /
Day of Week0-7 or SUN-SAT* , - / ? L #

Special Characters

CharacterDescriptionExample
*Every value* * * * * (every minute)
,List separator1,15 * * * * (minute 1 and 15)
-Range1-5 * * * * (minutes 1 through 5)
/Step values*/15 * * * * (every 15 minutes)
?No specific value (day fields)0 0 ? * MON
LLast0 0 L * * (last day of month)
WNearest weekday0 0 15W * * (weekday nearest 15th)
#Nth day of week0 0 * * 5#3 (3rd Friday)

Special Strings (shorthand)

StringEquivalentDescription
@rebootRun once at startup
@yearly0 0 1 1 *Once a year (Jan 1, midnight)
@annually0 0 1 1 *Same as @yearly
@monthly0 0 1 * *Once a month (1st, midnight)
@weekly0 0 * * 0Once a week (Sunday, midnight)
@daily0 0 * * *Once a day (midnight)
@midnight0 0 * * *Same as @daily
@hourly0 * * * *Once an hour (top of hour)

Common Schedules

ExpressionDescription
* * * * *Every minute
*/5 * * * *Every 5 minutes
*/15 * * * *Every 15 minutes
0 * * * *Every hour
0 */2 * * *Every 2 hours
0 0 * * *Every day at midnight
0 6 * * *Every day at 6:00 AM
0 9-17 * * 1-5Hourly, 9 AM–5 PM, Mon–Fri
0 0 * * 0Every Sunday at midnight
0 0 * * 1-5Every weekday at midnight
0 0 1 * *First of every month
0 0 1 1 *January 1st at midnight
30 4 1,15 * *4:30 AM on 1st and 15th
0 0 * * 1Every Monday at midnight
0 22 * * 5Every Friday at 10:00 PM

Crontab Commands

CommandDescription
crontab -eEdit current user’s crontab
crontab -lList current user’s crontab
crontab -rRemove current user’s crontab
crontab -u user -eEdit another user’s crontab

Environment & Tips

# Set shell
SHELL=/bin/bash

# Set PATH (cron has minimal PATH by default)
PATH=/usr/local/bin:/usr/bin:/bin

# Email output (set empty to disable)
MAILTO="user@example.com"
MAILTO=""

# Redirect output to log
* * * * * /path/script.sh >> /var/log/cron.log 2>&1

# Discard all output
* * * * * /path/script.sh > /dev/null 2>&1

# Use flock to prevent overlapping runs
* * * * * flock -n /tmp/job.lock /path/script.sh

System Cron Directories

PathDescription
/etc/crontabSystem crontab (has user field)
/etc/cron.d/Drop-in cron files
/etc/cron.daily/Scripts run daily
/etc/cron.hourly/Scripts run hourly
/etc/cron.weekly/Scripts run weekly
/etc/cron.monthly/Scripts run monthly