📖 Guide
Cron — Complete Reference
Cron scheduling reference covering syntax, field values, crontab management, and common schedule patterns.
63 commands across 9 categories
Cron SyntaxSpecial StringsField ValuesCommon SchedulesCrontab ManagementEnvironmentOutput & LoggingBest PracticesCommon Patterns
Cron Syntax
| Command | Description |
|---|---|
* * * * * | Five fields: minute hour day-of-month month day-of-week |
┌ minute (0-59)\n│ ┌ hour (0-23)\n│ │ ┌ day of month (1-31)\n│ │ │ ┌ month (1-12)\n│ │ │ │ ┌ day of week (0-7, 0&7=Sun) | Field order reference |
* | Wildcard — matches every value |
5,10,15 | List — matches specific values |
1-5 | Range — matches values 1 through 5 |
*/15e.g. */15 * * * * → every 15 minutes | Step — every 15th value |
1-30/5 | Range with step — every 5th value from 1 to 30 |
Special Strings
| Command | Description |
|---|---|
@reboot | Run once at startup |
@yearly / @annually | Run once a year (0 0 1 1 *) |
@monthly | Run once a month (0 0 1 * *) |
@weekly | Run once a week (0 0 * * 0) |
@daily / @midnight | Run once a day (0 0 * * *) |
@hourly | Run once an hour (0 * * * *) |
Field Values
| Command | Description |
|---|---|
Minute: 0-59 | Minute of the hour |
Hour: 0-23 | Hour of the day (0 = midnight) |
Day of Month: 1-31 | Day of the month |
Month: 1-12 or JAN-DEC | Month (names are case-insensitive) |
Day of Week: 0-7 or SUN-SAT | Day of week (0 and 7 both = Sunday) |
SUN=0, MON=1, TUE=2, WED=3, THU=4, FRI=5, SAT=6 | Day-of-week name to number mapping |
JAN=1, FEB=2, ..., NOV=11, DEC=12 | Month name to number mapping |
Common Schedules
| Command | Description |
|---|---|
0 * * * * | Every hour (at minute 0) |
*/5 * * * * | Every 5 minutes |
*/15 * * * * | Every 15 minutes |
0 */2 * * * | Every 2 hours |
0 9 * * * | Every day at 9:00 AM |
0 9 * * 1-5 | Weekdays at 9:00 AM |
0 0 * * 0 | Every Sunday at midnight |
0 0 1 * * | First day of every month at midnight |
30 2 * * * | Every day at 2:30 AM (common for backups) |
0 9,17 * * 1-5 | Weekdays at 9 AM and 5 PM |
Crontab Management
| Command | Description |
|---|---|
crontab -e | Edit current user's crontab |
crontab -l | List current user's crontab |
crontab -r | Remove current user's crontab (⚠️ no confirmation) |
crontab -u username -e | Edit another user's crontab (requires root) |
crontab file.txt | Replace crontab with contents of file |
crontab -l > backup.txt | Backup current crontab to file |
sudo ls /var/spool/cron/crontabs/ | List all user crontab files (Linux) |
cat /etc/crontab | View system-wide crontab (includes user field) |
Environment
| Command | Description |
|---|---|
SHELL=/bin/bash | Set shell for cron jobs (default is /bin/sh) |
PATH=/usr/local/bin:/usr/bin:/bin | Set PATH (cron has minimal PATH by default) |
MAILTO=user@example.com | Email output to this address |
MAILTO="" | Disable email output |
HOME=/home/user | Set working directory for jobs |
CRON_TZ=America/New_York | Set timezone for cron schedule (some implementations) |
Output & Logging
| Command | Description |
|---|---|
* * * * * /script.sh > /dev/null 2>&1 | Suppress all output (stdout + stderr) |
* * * * * /script.sh >> /var/log/job.log 2>&1 | Append all output to log file |
* * * * * /script.sh 2>> /var/log/errors.log | Log only errors (stderr) |
* * * * * /script.sh | logger -t myjob | Send output to syslog |
* * * * * date >> /tmp/cron.log && /script.sh >> /tmp/cron.log 2>&1 | Log with timestamp |
grep CRON /var/log/syslog | Check cron execution history (Linux) |
Best Practices
| Command | Description |
|---|---|
*/5 * * * * /usr/bin/flock -n /tmp/job.lock /script.sh | Prevent overlapping runs with flock |
0 3 * * * /usr/local/bin/backup.sh | Use absolute paths for commands |
0 2 * * * sleep $((RANDOM \% 600)) && /script.sh | Add random jitter to avoid thundering herd |
0 4 * * * chronic /script.sh | Only email on error (using moreutils chronic) |
0 * * * * timeout 300 /script.sh | Kill job if it runs longer than 5 minutes |
# Backup database nightly\n0 3 * * * /opt/scripts/backup.sh | Always add comments describing the job |
Common Patterns
| Command | Description |
|---|---|
0 3 * * * /usr/bin/mysqldump -u root mydb > /backups/db.sql | Nightly database backup |
*/10 * * * * /usr/bin/curl -sf https://hc-ping.com/UUID > /dev/null | Healthcheck ping every 10 minutes |
0 5 * * * find /tmp -mtime +7 -delete | Clean temp files older than 7 days |
0 */6 * * * certbot renew --quiet | Check SSL cert renewal every 6 hours |
0 0 * * 0 docker system prune -f | Weekly Docker cleanup |
*/30 * * * * /usr/bin/rsync -a /src/ /backup/ | Sync files every 30 minutes |
0 8 * * 1 /opt/scripts/weekly-report.sh | mail -s 'Report' user@co.com | Monday morning report email |
📖 Free, searchable command reference. Bookmark this page for quick access.