Cron syntax cheat sheet

On this page

Cron syntax is five fields separated by spaces: minute, hour, day of the month, month and day of the week, followed by the command to run. A star matches every value, and lists, ranges and steps pick some of them. This page holds the whole grammar in tables you can scan.

What are the five cron fields?

FieldAllowed valuesNotes
Minute0-59The minute of the hour the job starts.
Hour0-23A 24-hour clock in the scheduler's time zone.
Day of the month1-31A day that the month does not have, such as 31 in April, is skipped.
Month1-12 or JAN-DECNames are not case sensitive.
Day of the week0-7 or SUN-SAT0 and 7 both mean Sunday.

A crontab line is these five fields, then the command. A line such as 30 2 * * 1-5 /usr/local/bin/backup.sh runs the script at 02:30 on Monday to Friday. The cron expression translator reads any line back in plain English.

What do the special characters mean?

CharacterMeaningExample
*Every value of the field.* * * * * runs every minute.
,A list of values.0 8,12,18 * * * runs at 08:00, 12:00 and 18:00.
-An inclusive range.0 9-17 * * * runs at the start of every hour from 09:00 to 17:00.
/A step through a range, or through the whole field after a star.*/15 * * * * runs every 15 minutes, and 10-40/10 * * * * runs at minutes 10, 20, 30 and 40.

Combine them freely inside one field: 1-5,10-15/5 means 1 to 5, then 10, 15. A step counts from the start of its range, so */20 in the minute field runs at 0, 20 and 40, not every 20 minutes since the last run.

Which shortcuts does cron accept?

ShortcutSame asWhen it runs
@yearly0 0 1 1 *Once a year, at midnight on 1 January. Also written @annually.
@monthly0 0 1 * *Once a month, at midnight on the first.
@weekly0 0 * * 0Once a week, at midnight at the start of Sunday.
@daily0 0 * * *Once a day, at midnight. Also written @midnight.
@hourly0 * * * *Once an hour, at minute 0.

@reboot is different. It has no schedule: it runs once, when the cron daemon starts, usually at boot. Because it has no times to expect, a heartbeat check cannot watch it the way it watches a schedule. Not every scheduler reads these shortcuts, so check yours before you rely on one.

How do the day of the month and the day of the week combine?

crontab
0 9 1 * 1

When both day fields are restricted, standard Unix cron runs the job when either one matches. The line above does not mean "the first, if it is a Monday". It runs at 09:00 on the first of every month and also at 09:00 on every Monday. If you want only a Monday that falls on the first, schedule the job for every Monday and test the date in the script.

If one of the two fields is a star, the other alone decides. That is why 0 9 * * 1 is every Monday and 0 9 1 * * is the first of the month. Some schedulers treat the two fields differently, and Quartz requires a ? in one of them; see Quartz and Spring cron.

Which cron expressions are worth copying?

ExpressionRuns
* * * * *Every minute.
*/5 * * * *Every 5 minutes.
0 * * * *At the start of every hour.
0 0 * * *Every day at midnight.
30 2 * * 1-5At 02:30 on weekdays.
0 9 * * 1At 09:00 every Monday.
0 */6 * * *Every 6 hours, at 00:00, 06:00, 12:00 and 18:00.
0 0 1 * *At midnight on the first of every month.
15 3 * * 0At 03:15 every Sunday.
0 0 1 1 *At midnight on 1 January.

Each of these has its own page with the next runs and the daylight saving behavior in the cron expression examples. To build a line from pickers instead, use the crontab generator.

Can you use names for months and weekdays?

Yes, in Unix cron. 0 8 * * MON-FRI is the same as 0 8 * * 1-5, and 0 0 1 JAN * is the same as 0 0 1 1 *. Sunday is both 0 and 7, which is why a range such as 5-7 ends on Sunday.

How do you make sure the line really ran?

A crontab line gives no sign that it ran. Add a request to the end of the command, joined with && so that it is sent only after a successful run, and give it a timeout so that a lost request cannot hang the job:

crontab
30 2 * * 1-5 /usr/local/bin/backup.sh && curl -fsS --max-time 10 --retry 5 -o /dev/null https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10

CronMissed expects that request on the schedule in the line and alerts you when it is late. What is cron job monitoring? explains the idea.

Sources

Questions and answers

What is the order of the fields in a cron expression?
Minute, hour, day of the month, month, day of the week. Remember it as small to large, then the weekday last.
Is there a field for seconds or for the year?
Not in standard Unix cron. Quartz and Spring add a leading seconds field, and Quartz accepts an optional year. A line with six or seven fields is not a Unix cron line, and CronMissed checks accept the five-field form.
How do I run a job every 30 seconds with cron?
You cannot with one line, because the smallest unit is a minute. Two lines, one of them starting with sleep 30, do it; see cron every 30 seconds.
Know the moment a job goes quiet

Create a check, add one curl to the job, and CronMissed alerts you when a ping is late or reports a failure.

Start monitoring