Skip to content
BENIBIX Learn

Cron Expression

Infrastructure⌨️ Linux & the Command LineProcesses and Services

Also known as Cron Schedule, Cron Syntax, Crontab Syntax

Five fields that say when a scheduled job runs, like 0 3 * * *.

Think of it like

Think of it like a school timetable written in code. Each box says which day and hour.

Example

Jack wants a report at 9:30 on weekdays. He writes 30 9 * * 1-5, which means minute 30 of hour 9, Monday to Friday.

Why it matters

One wrong field can run a job every minute instead of once a day.

Definition

A cron expression is the time pattern in a cron job. It has five fields, in this order: minute, hour, day of the month, month and day of the week. A star means every value. So 0 3 * * * means minute 0 of hour 3, every day. Many tools beyond cron use the same five fields.

Example code

console
$ crontab -l
30 9 * * 1-5 /home/jack/report.sh
*/15 * * * * /home/jack/check.sh
The first job runs at 9:30 on weekdays. The second runs every 15 minutes.
Each of the five fields has its own place. Read them left to right: minute, hour, day, month, weekday.

Common mistake

Mixing up the order. The first field is the minute, not the hour.

Key takeaways

  1. 1
    Five fields. Minute, hour, day, month, weekday.
  2. 2
    Star means every. Any value matches.
  3. 3
    Minute first. Not the hour.

Learn it properly