Crontab Expressions Explained

Welcome to the Crontab Explained article, In this article I am explaining everything you need to know about crontab. A cron expression is a string of five fields separated by white space. Each field represents a set of time intervals at which a job or task should be executed.

The five fields, in order, represent:

  1. Minutes (0 – 59)
  2. Hours (0 – 23)
  3. Day of month (1 – 31)
  4. Month (1 – 12 or JAN-DEC)
  5. Day of week (0 – 7 or SUN-SAT, where both 0 and 7 represent Sunday)

Each field allows for single values, comma-separated lists, ranges, and special characters to represent time intervals. These special characters include:

  • Asterisk (*): Represents all possible values for that field.
  • Slash (/): Specifies intervals. For example, */15 in the minutes field means “every 15 minutes.”
  • Dash (-): Specifies a range. For example, 1-5 in the day of week field means Monday through Friday.
  • Comma (,): Specifies a list of values. For example, 1,15 in the day of month field means the 1st and 15th of the month.

You can combine these elements for precise scheduling of tasks. For example, a cron expression like 0 2 * * * would run a job at 2:00 AM every day, while 0 0 * * MON would run a job at midnight every Monday.

What is the Cron tab?

The cron command-line utility is a job scheduler on Unix-like operating systems such as Ubuntu, Centos, Alpine, and many others. System administrators use it to schedule housekeeping, Management, or Monitoring scripts.

What does cron * * * * * mean?

Cron * * * * * means that the scheduled script is going to run every minute.

Cron Job expression to run a job every 5 minutes

*/5 * * * * is used to run a cronjob every 5 minutes.

*/5 * * * *

Command to List all the cron jobs

crontab -l

Cron expression generator

You can use tools like Crontab Guru to generate cron expressions.

2 thoughts on “Crontab Expressions Explained”

Comments are closed.

Scroll to Top