CLI
Cron Cheatsheet
Quick reference for cron expression syntax, special strings, field values, and common scheduling patterns.
┌───────────── 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
| Field | Allowed Values | Special Characters |
|---|
| Minute | 0-59 | * , - / |
| Hour | 0-23 | * , - / |
| Day of Month | 1-31 | * , - / ? L W |
| Month | 1-12 or JAN-DEC | * , - / |
| Day of Week | 0-7 or SUN-SAT | * , - / ? L # |
Special Characters
| Character | Description | Example |
|---|
* | Every value | * * * * * (every minute) |
, | List separator | 1,15 * * * * (minute 1 and 15) |
- | Range | 1-5 * * * * (minutes 1 through 5) |
/ | Step values | */15 * * * * (every 15 minutes) |
? | No specific value (day fields) | 0 0 ? * MON |
L | Last | 0 0 L * * (last day of month) |
W | Nearest weekday | 0 0 15W * * (weekday nearest 15th) |
# | Nth day of week | 0 0 * * 5#3 (3rd Friday) |
Special Strings (shorthand)
| String | Equivalent | Description |
|---|
@reboot | — | Run once at startup |
@yearly | 0 0 1 1 * | Once a year (Jan 1, midnight) |
@annually | 0 0 1 1 * | Same as @yearly |
@monthly | 0 0 1 * * | Once a month (1st, midnight) |
@weekly | 0 0 * * 0 | Once a week (Sunday, midnight) |
@daily | 0 0 * * * | Once a day (midnight) |
@midnight | 0 0 * * * | Same as @daily |
@hourly | 0 * * * * | Once an hour (top of hour) |
Common Schedules
| Expression | Description |
|---|
* * * * * | 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-5 | Hourly, 9 AM–5 PM, Mon–Fri |
0 0 * * 0 | Every Sunday at midnight |
0 0 * * 1-5 | Every 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 * * 1 | Every Monday at midnight |
0 22 * * 5 | Every Friday at 10:00 PM |
Crontab Commands
| Command | Description |
|---|
crontab -e | Edit current user’s crontab |
crontab -l | List current user’s crontab |
crontab -r | Remove current user’s crontab |
crontab -u user -e | Edit 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
| Path | Description |
|---|
/etc/crontab | System 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 |