Cron cheatsheet
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 |
crontab -u user -l | List another user's crontab (root) |
sudo crontab -e -u www-data | Edit crontab as a specific user |
Field syntax
| Field | Values | Example |
|---|---|---|
| Minute | 0–59 | */5 every 5 minutes |
| Hour | 0–23 | 2 at 02:00 |
| Day of month | 1–31 | 1 first of the month |
| Month | 1–12 | * every month |
| Day of week | 0–7 (0 and 7 = Sunday) | 1-5 weekdays |
Special strings
| String | Equivalent | Meaning |
|---|---|---|
@reboot | — | Run once at startup |
@yearly / @annually | 0 0 1 1 * | Once a year |
@monthly | 0 0 1 * * | First day of month |
@weekly | 0 0 * * 0 | Every Sunday |
@daily / @midnight | 0 0 * * * | Every day at midnight |
@hourly | 0 * * * * | Every hour |
Common schedule examples
# Every day at 3:15 AM
15 3 * * * /usr/local/bin/backup.sh
# Every 10 minutes
*/10 * * * * /opt/app/healthcheck.sh
# Weekdays at 9 AM
0 9 * * 1-5 /usr/bin/report.sh
# First of month at midnight
0 0 1 * * /usr/local/bin/monthly-cleanup.sh
System cron locations
| Path | Description |
|---|---|
/etc/crontab | System-wide crontab (includes user field) |
/etc/cron.d/ | Per-package drop-in files |
/etc/cron.hourly/ | Scripts run hourly |
/etc/cron.daily/ | Scripts run daily |
/var/spool/cron/crontabs/ | User crontabs (Debian/Ubuntu) |
/var/spool/cron/ | User crontabs (RHEL/CentOS) |
Inspection & logs
| Command | Description |
|---|---|
systemctl status cron | Check cron service (Debian/Ubuntu) |
systemctl status crond | Check cron service (RHEL/CentOS) |
grep CRON /var/log/syslog | Cron run log (Debian/Ubuntu) |
grep CRON /var/log/cron | Cron run log (RHEL/CentOS) |
journalctl -u cron | systemd journal for cron unit |
Crontab environment lines
MAILTO=ops@example.com
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SHELL=/bin/bash
*/5 * * * * /usr/local/bin/job.sh >> /var/log/job.log 2>&1
Pro tips
- Always use absolute paths for scripts and binaries in cron jobs
- Redirect output to a log file — cron won't show errors on your terminal
- Use
flockto prevent overlapping runs of the same job - Test the exact command as the cron user:
sudo -u www-data /path/to/script.sh
Practice scenarios
Hands-on Cron scenarios on live Linux VMs: cron