Cron Syntax Cheat Sheet
Cron expression reference with schedules, special strings, field explanations, and common crontab patterns. Copy-ready examples.
Fields
| Directive | Description | Example |
|---|---|---|
| MIN HOUR DOM MON DOW | minute(0-59) hour(0-23) day(1-31) month(1-12) weekday(0-7) | |
| Any value (wildcard) | * * * * * → every minute | |
| Exact value | 5 * * * * → at minute 5 of every hour | |
| Multiple values | 0 1,13 * * * → 1:00 AM and 1:00 PM | |
| Range of values | 0 9-17 * * * → every hour 9 AM to 5 PM | |
| Step values (every nth) | */15 * * * * → every 15 minutes | |
| Step within range | 0 0 1-15/3 * * → days 1,4,7,10,13 |
Common Schedules
| Directive | Description | Example |
|---|---|---|
| Every minute | * * * * * /path/to/script.sh | |
| Every 5 minutes | */5 * * * * curl http://example.com/ping | |
| Every hour (at minute 0) | 0 * * * * /usr/bin/hourly-task | |
| Every day at midnight | 0 0 * * * /usr/bin/daily-backup | |
| Every day at 6 AM | 0 6 * * * /usr/bin/morning-report | |
| Every Sunday at midnight | 0 0 * * 0 /usr/bin/weekly-cleanup | |
| First day of every month | 0 0 1 * * /usr/bin/monthly-report | |
| Every January 1st | 0 0 1 1 * /usr/bin/yearly-task | |
| Hourly during business hours | 0 9-17 * * 1-5 → Mon-Fri 9AM-5PM | |
| Every weekday at midnight | 0 0 * * 1-5 /usr/bin/weekday-job | |
| Every 30 minutes | */30 * * * * /usr/bin/check-health |
Special Strings
| Directive | Description | Example |
|---|---|---|
| Run once at system startup | @reboot /usr/bin/start-service | |
| Once a year (0 0 1 1 *) | @yearly /usr/bin/annual-report | |
| Once a month (0 0 1 * *) | @monthly /usr/bin/monthly-cleanup | |
| Once a week (0 0 * * 0) | @weekly /usr/bin/weekly-backup | |
| Once a day (0 0 * * *) | @daily /usr/bin/daily-task | |
| Once an hour (0 * * * *) | @hourly /usr/bin/hourly-check |
Names
| Directive | Description | Example |
|---|---|---|
| Month names or numbers | 0 0 1 JAN,JUL * → Jan 1st and Jul 1st | |
| Day names (0 and 7 = Sunday) | 0 0 * * MON-FRI → weekdays only |
Commands
| Directive | Description | Example |
|---|---|---|
| Edit current user's crontab | crontab -e → opens in default editor | |
| List current user's cron jobs | crontab -l → show all scheduled jobs | |
| Remove all cron jobs | crontab -r → delete all (use with care!) | |
| Edit another user's crontab | sudo crontab -u www-data -e | |
| System-wide crontab file | Includes USER field: * * * * * root /cmd | |
| System cron job directory | Drop files here for system cron jobs | |
| Daily cron scripts directory | Scripts here run once daily (via anacron) |
Output
| Directive | Description | Example |
|---|---|---|
| Append output + errors to log | * * * * * /cmd >> /var/log/cron.log 2>&1 | |
| Discard all output | */5 * * * * /cmd > /dev/null 2>&1 | |
| Email output to address | MAILTO=admin@example.com (at top of crontab) | |
| Disable email notifications | MAILTO="" (no email for any job below) |
Environment
| Directive | Description | Example |
|---|---|---|
| Set PATH for cron environment | PATH=/usr/local/bin:/usr/bin:/bin | |
| Set shell for cron | SHELL=/bin/bash (default is /bin/sh) | |
| Set working directory | HOME=/var/www/app |
Best Practices
| Directive | Description | Example |
|---|---|---|
| Prevent overlapping runs | * * * * * flock -n /tmp/job.lock /usr/bin/long-task | |
| Always use absolute paths | /usr/bin/python3 /home/user/script.py | |
| Only output on error (moreutils) | */5 * * * * chronic /usr/bin/health-check |
Frequently asked questions
How do I read a cron expression?
Read left to right: minute, hour, day-of-month, month, day-of-week. '30 2 * * 1' means 'at minute 30, hour 2 (2:30 AM), any day of month, any month, on Monday'. Use crontab.guru for interactive visualization.
Why isn't my cron job running?
Top causes: 1) Wrong PATH (use absolute paths), 2) Permission issues (check file is executable), 3) Syntax error in crontab (check with crontab -l), 4) Wrong user (crontab -u), 5) Service not running (systemctl status cron). Check /var/log/syslog for 'CRON' entries.
What timezone does cron use?
Cron uses the system timezone by default. On modern systems, set TZ=America/New_York in your crontab to override. Be careful with DST: a 2:30 AM job might run twice or not at all during time changes.
How do I run a job every 2 hours?
Use '0 */2 * * *' which runs at minute 0 of every 2nd hour (0:00, 2:00, 4:00, ...). The */n syntax means 'every nth value'. You can combine: '0 */2 * * 1-5' runs every 2 hours on weekdays only.
What's the difference between cron.d and crontab?
crontab -e edits a per-user crontab. /etc/cron.d/ contains system-level cron files with an extra USER field. /etc/cron.daily/, .weekly/, .monthly/ are directories where you drop executable scripts that anacron runs at those intervals.
How do I run a cron job every 5 seconds?
Cron's minimum interval is 1 minute. For sub-minute scheduling, use a loop in a script: 'while true; do /cmd; sleep 5; done' managed by systemd, or use systemd timers which support sub-second accuracy. Alternatively, run a cron job every minute that internally sleeps.
Go from reference to real skills
Cheat sheets are great for quick lookups. Our in-depth courses take you from the fundamentals to professional-level mastery.
Browse all courses