ToolsOps

Cron expression examples for Linux and Unix

Practical cron expression examples for Linux and Unix: every 5 minutes, hourly, weekdays, monthly jobs and more.

What cron is and what it does

cron is the classic task scheduler on Unix and Linux systems. It reads a configuration file (the crontab) where each line contains a time expression and a command to run. When the system date and time match the expression, the command is fired.

This guide uses the five-field Unix/POSIX cron format: minute, hour, day-of-month, month and day-of-week. There is no seconds field. It is not compatible with extended dialects such as Quartz, which adds seconds and additional operators.

How to read a cron expression

A cron expression is a sequence of five fields separated by spaces. Each field controls one time unit. If every field matches the current date, the command runs.

┌──────── minute        (0-59)
│ ┌────── hour          (0-23)
│ │ ┌──── day-of-month  (1-31)
│ │ │ ┌── month         (1-12)
│ │ │ │ ┌ day-of-week   (0-7; 0 and 7 = Sunday)
│ │ │ │ │
* * * * *  command to execute

Cron fields in detail

  • Minute: 0–59.
  • Hour: 0–23 (24-hour clock).
  • Day-of-month: 1–31.
  • Month: 1–12 (names like JAN, FEB, ... also accepted).
  • Day-of-week: 0–7, where 0 and 7 mean Sunday (some implementations accept SUN, MON, ...).

Difference between *, */n, ranges and lists

  • * — any value in the field.
  • */n — every n units. Example: */5 in minutes = 0, 5, 10, 15, ...
  • a-b — inclusive range. Example: 9-17 in hours = 9, 10, ..., 17.
  • a,b,c — explicit list. Example: 1,15 in day-of-month = 1 and 15.

Common mistakes

  • Using 6 or 7 fields after copying a Quartz expression. Unix cron uses 5.
  • Assuming AND between day-of-month and day-of-week. Most implementations use OR.
  • Forgetting the timezone. Cron evaluates in the process TZ, not UTC.
  • Not redirecting output. If the command prints, cron emails the system mailbox.
  • Permissions: if the command is a script, it needs the execute bit and an absolute path.

Linux cron vs Quartz and other formats

Classic Unix/Linux cron works with 5 fields and minute resolution. Quartz, used in Java/Spring applications, adds a seconds field (and optionally a year), accepting 6 or 7 fields. Characters such as L, W or # are Quartz extensions and are not available in POSIX cron. If you copy an expression between systems, validate the field count first.

Common examples table

Copy any expression and paste it into the generator to preview the next runs.

ExpressionMeaningUse case
* * * * *Every minuteDev monitoring or smoke tests.
*/5 * * * *Every 5 minutesService polling or lightweight sync.
0 * * * *Every hour on the hourLog rotation or hourly cache clean-up.
0 9 * * *Every day at 09:00Daily summary email.
0 9 * * 1-5Monday to Friday at 09:00Weekday-only jobs.
0 0 * * 0Every Sunday at midnightWeekly maintenance off-hours.
0 0 1 * *1st day of every month at midnightMonthly billing or accounting cut-off.
0 0 1 1 *January 1st at midnightAnnual counter reset.
*/15 9-17 * * 1-5Every 15 minutes during business hoursFrequent checks only during the workday.
0 2 * * *Every day at 02:00Nightly backups.

Use the cron expression generator

Next steps

If your cron job runs a script, check file permissions with the chmod calculator. Make sure the file is executable (chmod +x script.sh) before scheduling the job.

Frequently asked questions

Which cron format does this guide use?
The Unix/POSIX five-field format: minute, hour, day-of-month, month and day-of-week. No seconds field. This is not the Quartz format used by Spring or some Java schedulers.
What happens if I combine day-of-month and day-of-week?
Most Unix/POSIX implementations use OR semantics: the job runs when EITHER field matches. For instance, `0 0 1 * 1` runs on the 1st of every month OR every Monday, not only when a Monday falls on the 1st.
Which timezone is the expression evaluated in?
Cron evaluates the expression in the timezone of the process running it (usually the system TZ). If you need a different zone, set the TZ environment variable or wrap the command so TZ is set first.
What does `*/n` mean?
The `*/n` operator means every `n` units within the field range. For example, `*/15` in the minutes field is equivalent to `0,15,30,45`.
What's the most common mistake when writing a cron expression?
Confusing day-of-week (0 = Sunday in most Unix implementations) or assuming `0 0 1 * 1` is AND. Also using 7 fields after copy-pasting Quartz expressions; Unix cron has 5.