A crontab line is five time fields followed by the command:
┌───────── 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 3 * * 1 /usr/local/bin/weekly-report.sh
This runs the script at 3:00 every Monday. In the day of week field, Sunday is both 0 and 7. To build a line by picking a schedule, use the cron expression generator; to check one, the cron expression tester.
Operators
| Symbol | Meaning | Example |
|---|---|---|
* | Every value | * * * * * runs every minute |
, | A list | 0,30 * * * * runs at minute 0 and 30 |
- | A range | 0 9-17 * * * runs on the hour from 9:00 to 17:00 |
/ | A step | */15 * * * * runs at minute 0, 15, 30 and 45 |
They combine: 0 8-18/2 * * 1-5 runs every 2 hours from 8:00 to 18:00, Monday to Friday. A step counts from the start of the range, so */7 in the minute field runs at 0, 7, 14 ... 56 and then again at 0, which is 4 minutes later. To start at minute 5, write 5-59/15.
Month and day names
The month and day of week fields also take the first three letters of the name, in any case: JAN to DEC and SUN to SAT. 0 9 * * MON is the same as 0 9 * * 1. The cron on Debian and Ubuntu doesn't accept names in lists or ranges, so MON-FRI may fail there; 1-5 works everywhere.
Special strings
| String | Same as |
|---|---|
@reboot | Once, when cron starts after boot |
@yearly or @annually | 0 0 1 1 * |
@monthly | 0 0 1 * * |
@weekly | 0 0 * * 0 |
@daily or @midnight | 0 0 * * * |
@hourly | 0 * * * * |
Day of month and day of week together
When both day fields are set, cron runs on any day that matches either one. 0 9 1 * 1 runs on the 1st of every month and also on every Monday. To run only on the first Monday of the month, set the day of month to 1-7, leave the day of week as *, and check the weekday in the command:
0 9 1-7 * * [ "$(date +\%u)" = 1 ] && /usr/local/bin/monthly.sh
Other lines in a crontab
| Line | What it does |
|---|---|
# comment | A comment. Only at the start of a line; text after a command is part of the command. |
PATH=/usr/local/bin:/usr/bin:/bin | Sets the PATH for the lines below it. Cron's default is short. |
SHELL=/bin/bash | Runs commands with bash instead of sh. |
MAILTO=you@example.com | Where cron mails the output. MAILTO="" turns mail off. |
CRON_TZ=Europe/Paris | Time zone for the schedule. Supported by cronie (Red Hat based systems), not by the cron on Debian and Ubuntu. |
In /etc/crontab and /etc/cron.d/, each line has a sixth field before the command: the user to run as.
0 3 * * * root /usr/local/bin/backup.sh
Write % as \% in the command; a bare % ends the command and starts standard input.
Examples
| Expression | Runs |
|---|---|
*/5 * * * * | Every 5 minutes |
0 * * * * | Every hour, on the hour |
0 */6 * * * | Every 6 hours: 0:00, 6:00, 12:00, 18:00 |
30 2 * * * | Every day at 2:30 |
0 9 * * 1-5 | Weekdays at 9:00 |
0 0 * * 0 | Sundays at midnight |
0 0 1 * * | The 1st of every month at midnight |
0 0 1 1 * | January 1st at midnight |
Each common schedule has its own page with variations: cron schedules.
Cron formats that are not crontab
| Where | Difference |
|---|---|
| GitHub Actions | Five fields like crontab. UTC unless a timezone key next to cron sets another zone. |
| Kubernetes CronJob | Five fields like crontab. A timeZone setting picks the zone. |
| Quartz (Java, Spring) | Six or seven fields: seconds first, an optional year last. Adds ?, L, W and #. |
| AWS EventBridge | Six fields with a year, written cron(0 12 * * ? *). One of the two day fields must be ?. |
A correct line can still stop running
Syntax is the easy part. A server rebuilt without its crontab or a script that starts failing gives no error anywhere. Add a heartbeat ping after the command, and you get an alert when a run is missed:
0 3 * * 1 /usr/local/bin/weekly-report.sh && curl -fsS -m 10 -X POST https://api.failover.io/heartbeat/<your-monitor-id>
Frequently asked questions
What is the crontab format?
Five fields, minute, hour, day of month, month and day of week, followed by the command. 30 2 * * * means 2:30 every day.
What does */5 mean in cron?
Every 5th value of that field. In the minute field, */5 runs at minute 0, 5, 10 and so on, every 5 minutes.
Is Sunday 0 or 7 in cron?
Both. 0 and 7 both mean Sunday in the day of week field.
Can cron run every 30 seconds?
Not with crontab, which counts in minutes. Run two lines, the second starting with sleep 30;, or use a systemd timer.
Why does my cron job run on the wrong days?
If you set both the day of month and the day of week, cron runs when either matches. Leave one of them as *.