How-to

Cron Expressions, Field by Field

Five fields decide when a job runs. Once you can read them aloud, writing any schedule takes seconds, and the few traps become easy to spot.

What are the five fields?

A cron expression is five space-separated fields followed by the command. From left to right: minute, hour, day of month, month and day of week. A star means "every". The line runs when the current time matches all fields, checked once a minute.

FieldAllowed valuesNotes
Minute0 to 59
Hour0 to 2324-hour clock, server time zone
Day of month1 to 31Days a month lacks simply never match
Month1 to 12 or jan to decNames are case-insensitive
Day of week0 to 7 or sun to sat0 and 7 both mean Sunday

So 30 2 * * * reads "at minute 30 of hour 2, every day of every month, any weekday", or simply 02:30 daily.

How do ranges, lists and steps work?

  • Range: 9-17 in the hour field means every hour from 9 through 17.
  • List: 1,15 in the day-of-month field means the 1st and the 15th.
  • Step: */10 in the minute field means minutes 0, 10, 20, 30, 40 and 50.
  • Stepped range: 8-18/2 in the hour field means 8, 10, 12, 14, 16 and 18.

Combine them freely: 0,30 9-17 * * mon-fri runs on the hour and half hour during weekday office hours.

Which common schedules should I keep handy?

ExpressionRuns
*/5 * * * *Every five minutes
7 * * * *Every hour at minute 7
15 3 * * *Daily at 03:15
0 4 * * 0Sundays at 04:00
45 1 1 * *01:45 on the first of each month
0 6 1 1,4,7,10 *Quarterly, 06:00 on the first day
20 0 * * 1-5Weeknights at 00:20

Odd minutes such as 7 or 15 are a small courtesy: if every job on every server runs at minute 0, shared services such as package mirrors and APIs see a spike at the top of the hour.

What is the day-of-month and weekday trap?

When both day fields are restricted, cron runs the job when either one matches, not when both do. 0 9 1-7 * mon looks like "the first Monday of the month", but it actually runs on days 1 to 7 and on every Monday. To get the first Monday, restrict only one field and test the other in the command:

0 9 1-7 * * [ "$(date +\%u)" = 1 ] && /usr/local/bin/monthly-report

Note the backslash before %. In a crontab line, an unescaped percent sign becomes a newline, which silently breaks commands that use date formats.

What do the @ shortcuts mean?

Most cron implementations accept named schedules: @hourly (0 * * * *), @daily or @midnight (0 0 * * *), @weekly (0 0 * * 0), @monthly, @yearly and @reboot, which runs once when the cron daemon starts. @reboot is handy for small helpers, though a proper systemd service is the better home for anything that must keep running.

Which time zone does cron use?

The system time zone by default. Check it with timedatectl. Many admins keep servers on UTC so logs from machines in Phoenix, Amsterdam and Singapore line up without conversion. If one job must follow local business hours, cronie on Rocky Linux and AlmaLinux understands a CRON_TZ=America/Chicago line above it. Around daylight saving changes, jobs scheduled between 01:00 and 03:00 local time can run twice or be skipped, another argument for UTC.

How do cron expressions map to systemd timers?

systemd uses OnCalendar= with a more readable format: *-*-* 03:15:00 for daily at 03:15, Mon..Fri *-*-* 00:20 for weeknights, *:0/5 for every five minutes. Test any expression with systemd-analyze calendar 'Mon..Fri *-*-* 00:20', which prints the next run time. Timers also offer Persistent=true to catch up runs missed while the machine was off.

How do I check an expression before trusting it?

Read it aloud field by field, then let the machine confirm. Put the job in place with a harmless command such as logger cron-test, wait for the first expected run and look for the line with journalctl -t cron-test. Setting up the crontab itself is covered in Set up a cron job.

Keep Reading

Set up a cron job

Create a cron job that actually runs: crontab -e, full paths, environment, logging, locking against overlap and mail-free alerts.

Open

List all cron jobs

Find every scheduled job on a machine: user crontabs, system files, cron.d, periodic folders, anacron and systemd timers.

Open

Back up data with rsync

Build dated, space-saving snapshot backups with rsync and hard links, pull them from a second machine and test restores.

Open

Latency

Why distance sets the floor for ping time, how to estimate round trips between our six cities and how to choose a location.

Open

FAQ

Quick Answers

Every 15 units of that field. In the minute field it means minutes 0, 15, 30 and 45.

Both. Day of week accepts 0 and 7 for Sunday.

When day of month and day of week are both restricted, cron matches either one. Restrict one field and test the other in the command.

Cron turns unescaped % into a newline. Write \% inside crontab lines.

The system time zone. Many admins keep servers on UTC to avoid daylight saving surprises.