Cron cheat sheet
Cron runs commands on a schedule. Edit your jobs with crontab -e. Explain any expression with the cron explainer.
The five fields
* * * * * command- minute hour day-of-month month day-of-week
minute- 0 to 59
hour- 0 to 23
day of month- 1 to 31
month- 1 to 12
day of week- 0 to 7 (0 and 7 are Sunday)
Operators
*- Every value
5,35- A list: at 5 and 35
9-17- A range: 9 to 17
*/15- Every 15 units
10-50/10- Every 10 within a range
Ready-to-copy schedules
*/5 * * * *- Every 5 minutes
0 * * * *- Every hour, on the hour
30 2 * * *- Every day at 02:30
0 9 * * 1-5- Weekdays at 09:00
0 0 1 * *- First day of every month at midnight
0 0 * * 0- Every Sunday at midnight
Special strings
@reboot- Once at startup
@daily- Once a day (0 0 * * *)
@hourly- Once an hour (0 * * * *)
@weekly- Once a week (0 0 * * 0)
@monthly- Once a month (0 0 1 * *)
Manage jobs
crontab -e- Edit your jobs
crontab -l- List your jobs
crontab -r- Remove all your jobs (no confirmation)
MAILTO=you@example.com- First line: where output is mailed
0 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1- Log output and errors to a file
Common mistakes
Use absolute paths- Cron has a minimal PATH, so use /usr/bin/python3 not python3
Escape % as \%- A bare % in a command is treated as a newline
Both day fields set- Day-of-month and day-of-week match with OR, not AND
Times follow the server clock- Check the time zone with timedatectl
Learn it properly