Skip to content
hostcomplex

Cron Syntax Explained

Maarten Soetens 3 min read

The Five Time Fields in a Crontab Entry

Cron syntax is the format used to describe when a cron job runs. Each line in a crontab file starts with five time fields, followed by the command to run. The fields always appear in the same order:

  • Minute: 0 to 59
  • Hour: 0 to 23, using a 24-hour clock
  • Day of the month: 1 to 31
  • Month: 1 to 12
  • Day of the week: 0 to 7, where both 0 and 7 mean Sunday

A schedule reads from left to right. The entry 30 14 * * * therefore means minute 30 of hour 14, on every day. Many systems also accept short day and month names, but the numbers work everywhere. The schedule follows the server's local time zone, so a job set for 14:30 runs at 14:30 on the server clock, which may differ from the time your visitors or team use. For background on the scheduler itself, read the guide to cron jobs.

Special Characters for Steps, Ranges and Lists

Four characters make the time fields more flexible:

  • The asterisk (*) matches every possible value. An asterisk in the hour field means every hour.
  • The slash (/) sets a step. */15 in the minute field means every 15 minutes: at 0, 15, 30 and 45.
  • The hyphen (-) defines a range. 9-17 in the hour field covers the hours from 9:00 through 17:00.
  • The comma (,) separates a list of values. 1,15 in the day-of-month field means the 1st and the 15th.

These characters can be combined. 0-30/10 in the minute field means minutes 0, 10, 20 and 30 within each hour.

Worked Examples and Shortcuts for Common Schedules

Reading a schedule becomes easier with a few examples. Each line below shows only the schedule, without the command:

  • 0 3 * * * runs once a day at 03:00.
  • */15 * * * * runs every 15 minutes, all day.
  • 30 8 * * 1-5 runs at 08:30 from Monday to Friday.
  • 0 0 1 * * runs at midnight on the first day of each month.

Cron also accepts shortcuts that replace the five fields. @reboot runs once when the system starts, @hourly runs at the top of every hour, and @daily runs once a day at midnight. @weekly, @monthly and @yearly follow the same pattern. Not every cron version supports every shortcut, so check the documentation for the system in use. Timers in systemd use a different format.

One rule often surprises people. If both the day-of-month and day-of-week fields are restricted, most cron versions run the job when either condition matches, not only when both do. The entry 0 12 13 * 5 therefore runs at noon on the 13th of every month and also at noon on every Friday.

Frequently asked questions

What does an asterisk mean in a cron schedule?

An asterisk means every possible value for that field. In 0 3 * * *, the asterisks in the last three fields mean every day of the month, every month and every day of the week, so the job runs at 03:00 daily. An asterisk in the minute field would instead run the job every minute of that hour.

Why is my cron job running at the wrong time?

The most common cause is the time zone. Cron uses the server's local time zone, which may differ from yours. Check the server's time zone setting before changing the schedule. Daylight saving time changes can also affect the job, because some cron versions may skip or repeat runs during the switch.

  • Two-Factor Authentication

    Two factor authentication hosting adds a second check to control panel, domain and CMS logins. Learn which methods are strongest and why 2FA helps.

  • What Is an A Record?

    What is an A record? Learn how this DNS record maps a hostname to an IPv4 address, why domains use several A records and the root and www pattern.

  • Billing and Automation Platforms

    What is WHMCS? Learn how this commercial billing and automation platform helps hosts sell plans, collect payments and create accounts automatically.