DEV Community

Sam
Sam

Posted on

Cron Expressions Explained: A Beginner-Friendly Guide with Examples

If you have ever needed to run a task automatically every few minutes, every day, or every Monday morning, you have probably come across cron expressions.

Cron is widely used for scheduling recurring tasks on Linux servers, backend systems, CI/CD jobs, and automation workflows.

A cron expression may look confusing at first:

*/5 * * * *
Enter fullscreen mode Exit fullscreen mode

But once you understand the five fields, it becomes much easier.


What Is a Cron Expression?

A standard Unix cron expression normally contains five fields:

* * * * *
│ │ │ │ │
│ │ │ │ └── Day of week
│ │ │ └──── Month
│ │ └────── Day of month
│ └──────── Hour
└────────── Minute
Enter fullscreen mode Exit fullscreen mode

Each field controls when the command should run.

For example:

0 9 * * *
Enter fullscreen mode Exit fullscreen mode

means:

Run every day at 9:00 AM.


Understanding the Five Fields

The standard structure is:

minute hour day-of-month month day-of-week
Enter fullscreen mode Exit fullscreen mode

For example:

30 14 * * *
Enter fullscreen mode Exit fullscreen mode

means:

Minute: 30
Hour: 14
Day of month: every day
Month: every month
Day of week: every day
Enter fullscreen mode Exit fullscreen mode

So the job runs every day at:

14:30
Enter fullscreen mode Exit fullscreen mode

or:

2:30 PM
Enter fullscreen mode Exit fullscreen mode

The Asterisk *

The * means:

every possible value
Enter fullscreen mode Exit fullscreen mode

For example:

* * * * *
Enter fullscreen mode Exit fullscreen mode

means:

Run every minute.

This is usually not something you want in production unless the task is designed to run that frequently.


Run Every 5 Minutes

*/5 * * * *
Enter fullscreen mode Exit fullscreen mode

The */5 means:

every 5 minutes
Enter fullscreen mode Exit fullscreen mode

So the job runs at:

00
05
10
15
20
25
...
Enter fullscreen mode Exit fullscreen mode

minutes past every hour.


Run Every Hour

0 * * * *
Enter fullscreen mode Exit fullscreen mode

This means:

Run at minute 0 of every hour.

Examples:

10:00
11:00
12:00
13:00
Enter fullscreen mode Exit fullscreen mode

Run Every Day at Midnight

0 0 * * *
Enter fullscreen mode Exit fullscreen mode

This runs every day at:

00:00
Enter fullscreen mode Exit fullscreen mode

A common use case is a nightly cleanup or backup task.


Run Every Day at 9 AM

0 9 * * *
Enter fullscreen mode Exit fullscreen mode

This means:

Minute: 0
Hour: 9
Enter fullscreen mode Exit fullscreen mode

So it runs every day at:

09:00
Enter fullscreen mode Exit fullscreen mode

Run Every Monday at 9 AM

0 9 * * 1
Enter fullscreen mode Exit fullscreen mode

In many cron implementations:

0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday
Enter fullscreen mode Exit fullscreen mode

So:

0 9 * * 1
Enter fullscreen mode Exit fullscreen mode

means:

Run every Monday at 9:00 AM.


Run on the First Day of Every Month

0 0 1 * *
Enter fullscreen mode Exit fullscreen mode

This means:

Run at midnight on the first day of every month.

This can be useful for:

  • monthly reports
  • billing jobs
  • cleanup tasks
  • data archival

Run Every 15 Minutes During Working Hours

You can combine values:

*/15 9-17 * * 1-5
Enter fullscreen mode Exit fullscreen mode

This means:

Every 15 minutes
Between 9 AM and 5 PM
Monday through Friday
Enter fullscreen mode Exit fullscreen mode

This is a good example of how cron expressions can become powerful while still staying compact.


Common Cron Symbols

A few symbols appear frequently:

*     every value
,     multiple values
-     range
/     step value
Enter fullscreen mode Exit fullscreen mode

Examples:

1,3,5
Enter fullscreen mode Exit fullscreen mode

means:

1, 3, and 5
Enter fullscreen mode Exit fullscreen mode

Example:

1-5
Enter fullscreen mode Exit fullscreen mode

means:

1 through 5
Enter fullscreen mode Exit fullscreen mode

Example:

*/10
Enter fullscreen mode Exit fullscreen mode

means:

every 10 units
Enter fullscreen mode Exit fullscreen mode

Common Cron Examples

*/5 * * * *
Enter fullscreen mode Exit fullscreen mode

Every 5 minutes.

0 * * * *
Enter fullscreen mode Exit fullscreen mode

Every hour.

0 0 * * *
Enter fullscreen mode Exit fullscreen mode

Every day at midnight.

0 9 * * 1-5
Enter fullscreen mode Exit fullscreen mode

Every weekday at 9 AM.

0 0 1 * *
Enter fullscreen mode Exit fullscreen mode

First day of every month.

30 18 * * 5
Enter fullscreen mode Exit fullscreen mode

Every Friday at 6:30 PM.


A Common Mistake: Cron Timezones

Cron expressions themselves normally describe a schedule, but the actual execution timezone depends on the system running the cron job.

For example:

0 9 * * *
Enter fullscreen mode Exit fullscreen mode

means 9 AM according to the timezone configured on the server or scheduler.

This can cause unexpected behavior when:

  • your server is using UTC
  • your users are in another timezone
  • daylight saving time changes
  • your cloud platform uses a different timezone

Always check the timezone used by your scheduler.


Cron Syntax Can Vary

Not every cron implementation behaves exactly the same.

Traditional Unix cron commonly uses five fields:

* * * * *
Enter fullscreen mode Exit fullscreen mode

But some systems add an extra field for seconds:

* * * * * *
Enter fullscreen mode Exit fullscreen mode

Other platforms may have different rules for day-of-week values or special syntax.

So always check the documentation for the platform you are using.


A Tool I Built for Testing Cron Expressions

While working with cron expressions, I wanted a quick way to understand a schedule and preview upcoming run times.

So I built a Cron Expression Tester as part of my project, YBS — Your Browser Suite.

👉 Try the Cron Expression Tester

It helps you:

  • test cron expressions
  • understand each field
  • preview upcoming run times
  • catch scheduling mistakes quickly

I also built a Cron Expression Generator for creating cron expressions using simple controls:

👉 Try the Cron Expression Generator


Final Thoughts

Cron expressions can look cryptic at first, but most schedules come down to understanding these five fields:

minute hour day-of-month month day-of-week
Enter fullscreen mode Exit fullscreen mode

Once you get comfortable with *, ranges, lists, and step values, cron becomes a very useful tool for automation.

What cron schedule do you use most often?

Share your examples in the comments. 👇

Top comments (0)