Cron Syntax Explained (With Examples)
Cron runs scheduled jobs on Linux, and its syntax is deceptively small — five fields and a command. Most cron bugs come from misreading one field or misusing the */N step value. Here's the whole thing, with examples you can copy.
The five fields
* * * * * command
| | | | |
| | | | +-- day of week (0-7, 0 and 7 = Sunday)
| | | +---- month (1-12)
| | +------ day of month (1-31)
| +-------- hour (0-23)
+---------- minute (0-59)
A * means "every". Read left to right: minute, hour, day-of-month, month, day-of-week.
Examples you'll actually use
0 2 * * * # 02:00 every day
*/5 * * * * # every 5 minutes
0 */6 * * * # every 6 hours, on the hour
30 4 * * 0 # 04:30 on Sundays
0 9 1 * * # 09:00 on the 1st of each month
15 14 * * 1-5 # 14:15 Monday to Friday
The */N gotcha
This is the single most common cron mistake:
5 * * * *= "at minute 5 of every hour" → runs once an hour.*/5 * * * *= "every 5 minutes" → runs 288 times a day.
If a job that should run constantly only fires hourly (or vice versa), check for a missing */.
Where crontabs live
- Per user:
crontab -llists the current user's jobs;crontab -eedits them. - System-wide:
/etc/crontaband files in/etc/cron.d/. These add a user field between day-of-week and the command:
0 2 * * * root /usr/local/bin/backup.sh
Forgetting that user field is a classic reason a system cron job silently never runs.
Debugging a job that won't run
- Is it in the right crontab? (
crontab -lvs/etc/crontab). - Is the schedule what you think? Re-read the five fields — especially day-of-month (field 3) vs day-of-week (field 5).
- Does the command work with cron's minimal
PATH? Use absolute paths. - Check the logs (
/var/log/syslogorjournalctl) for the cron run.
Practise reading and fixing schedules
The Cron & Scheduling arc in Terminal Trials has you decode real schedules and fix a broken one (the */5 gotcha included) in a safe simulated shell — free, in your browser.
Liked this? ShellQuest turns these mental models into puzzles and labs you can actually practise.
Join the waitlist