Crontab expression reference
Complete reference for crontab time expression fields, special strings, and environment variables with working examples.
Complete reference for crontab scheduling syntax, including the five time fields, special characters, shorthand strings, and environment variables.
Crontab Time Expression Fields
The crontab time expression consists of five fields that define when the cron daemon executes a job. Each field accepts integers, ranges, lists, and step values.
┌───────────── minute (0–59)
│ ┌───────────── hour (0–23)
│ │ ┌───────────── day of month (1–31)
│ │ │ ┌───────────── month (1–12)
│ │ │ │ ┌───────────── day of week (0–7, where 0 and 7 both represent Sunday)
│ │ │ │ │
* * * * * command| Field | Crontab field name | Allowed values | Description |
|---|---|---|---|
| 1 | Minute | 0–
59 | Crontab triggers the job when the system clock minute matches this value |
| 2 | Hour | 0–
23 | Crontab uses 24-hour format;
0 is midnight,
13 is 1:00 PM |
| 3 | Day of month | 1–
31 | Crontab runs the job on this calendar day; values beyond the month's last day are skipped |
| 4 | Month | 1–
12 or
jan–
dec | Crontab accepts numeric or three-letter abbreviated month names |
| 5 | Day of week | 0–
7 or
sun–
sat | Crontab treats both
0 and
7 as Sunday; accepts three-letter abbreviated day names |
Crontab Special Characters
The crontab expression parser supports four special characters within any time field.
| Character | Crontab meaning | Example | Result |
|---|---|---|---|
* | Crontab matches every possible value for the field | * * * * * | Crontab runs the job every minute of every hour of every day |
, | Crontab matches a list of specific values | 0,15,30,45 * * * * | Crontab runs the job at minute 0, 15, 30, and 45 of every hour |
- | Crontab matches a contiguous range of values | 0 9-17 * * * | Crontab runs the job at the top of every hour from 9:00 AM to 5:00 PM |
/ | Crontab matches at step intervals within a range | */10 * * * * | Crontab runs the job every 10 minutes (minute 0, 10, 20, 30, 40, 50) |
Crontab Common Schedule Examples
The crontab expression syntax combines the five time fields into schedules. These are the most frequently used crontab patterns.
| Crontab expression | Schedule description | Use case |
|---|---|---|
0 * * * * | Crontab runs the job at minute 0 of every hour | Hourly health checks, log aggregation |
0 2 * * * | Crontab runs the job at 2:00 AM every day | Nightly database backups, report generation |
*/5 * * * * | Crontab runs the job every 5 minutes | Service monitoring, uptime checks |
0 0 * * 0 | Crontab runs the job at midnight every Sunday | Weekly maintenance tasks, full backups |
0 0 1 * * | Crontab runs the job at midnight on the first day of every month | Monthly reports, invoice generation |
30 4 * * 1-5 | Crontab runs the job at 4:30 AM Monday through Friday | Weekday-only batch processing |
0 */6 * * * | Crontab runs the job every 6 hours (at 0:00, 6:00, 12:00, 18:00) | Certificate renewal checks, cache purging |
0 9 * * 1 | Crontab runs the job at 9:00 AM every Monday | Weekly team reports |
Crontab Special Shorthand Strings
The crontab parser on most Linux distributions accepts shorthand strings in place of the five-field expression. These crontab shortcuts replace the entire time specification.
| Crontab shorthand | Equivalent expression | Schedule description |
|---|---|---|
@reboot | N/A | Crontab runs the job once when the system boots; does not repeat |
@yearly | 0 0 1 1 * | Crontab runs the job at midnight on January 1 |
@monthly | 0 0 1 * * | Crontab runs the job at midnight on the first day of each month |
@weekly | 0 0 * * 0 | Crontab runs the job at midnight every Sunday |
@daily | 0 0 * * * | Crontab runs the job at midnight every day |
@hourly | 0 * * * * | Crontab runs the job at minute 0 of every hour |
Crontab Environment Variables
The crontab file accepts environment variable assignments before the job entries. The cron daemon applies these variables to all jobs that follow the assignment.
| Variable | Crontab behavior | Default | Example |
|---|---|---|---|
PATH | Crontab uses this value to locate executables in job commands | /usr/bin:/bin | PATH=/usr/local/bin:/usr/bin:/bin |
SHELL | Crontab uses this shell to execute job commands | /bin/sh | SHELL=/bin/bash |
MAILTO | Crontab sends job output as email to this address; set to
"" to suppress email | Owner's local mailbox | MAILTO=admin@example.com |
CRON_TZ | Crontab evaluates time expressions in this timezone instead of the system timezone | System timezone | CRON_TZ=America/New_York |
HOME | Crontab uses this directory as the working directory for job commands | Owner's home directory | HOME=/opt/app |
Crontab File Format
A complete crontab file combines environment variables and job entries. The cron daemon reads the file from top to bottom and applies variables to all subsequent jobs.
# Crontab environment variables
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=admin@example.com
# Crontab job entries
0 2 * * * /home/user/scripts/backup.sh >> /home/user/logs/backup.log 2>&1
*/5 * * * * /home/user/scripts/healthcheck.sh >> /home/user/logs/health.log 2>&1
@reboot /home/user/scripts/startup.shThe crontab file must end with a newline character. The cron daemon ignores the last line if it does not end with a newline — this is a common cause of crontab jobs not running.