Linux cron job syntax: the five fields, explained
A crontab is Linux's task schedule: each line says "when" followed by "what". The syntax looks cryptic once, but it is five time fields followed by the command. This guide is built on the official crontab(5) manual page.
The five fields
| Field | Allowed values |
|---|---|
| Minute | 0-59 |
| Hour | 0-23 |
| Day of month | 1-31 |
| Month | 1-12 |
| Day of week | 0-7 (0 and 7 are Sunday) |
An asterisk * means "every possible value" in that field.
Examples you can now read
# every hour at minute 30 30 * * * * /home/sam/backup.sh # daily at 2:15 AM 15 2 * * * /home/sam/cleanup.sh # every Monday at 9:00 AM 0 9 * * 1 /home/sam/report.sh
Read left to right: minute, hour, day of month, month, day of week.
The day-of-month / day-of-week rule
A subtle point from the manual: the command runs when the minute, hour and month fields all match, and at least one of the two day fields (day of month or day of week) matches. Writing both day fields together can mean "or", not "and", so be careful when combining them.
Edit and inspect
crontab -e # edit your schedule crontab -l # list it
cron checks the tables every minute, so nothing needs a restart after saving.
Common mistakes
- Relative paths: cron does not run from your project folder; use absolute paths everywhere.
- Environment variables: cron's environment is sparser than your interactive shell; declare PATH inside the script.
- Silent failure: redirect output to a log file so you know when a job fails.
Related: log into your server with SSH keys and the Arabic version of this guide.
