DEV Community

Christophe Canon
Christophe Canon

Posted on

Demystifying Unix Cron Expressions: A Complete Beginner's Guide

Master the standard 5-part crontab syntax with practical examples, special characters (*, /, -, ,), and best practices for scheduled server jobs.

Automating recurring tasks—such as daily database backups, hourly cache clearing, or weekly newsletter dispatches—is a staple of backend engineering. On Unix and Linux systems, the cron daemon is the undisputed standard.

The 5-Part Cron Syntax Anatomy

A standard crontab schedule entry consists of five positional fields followed by the command to execute:

┌───────────── Minute (0 - 59)
│ ┌───────────── Hour (0 - 23)
│ │ ┌───────────── Day of Month (1 - 31)
│ │ │ ┌───────────── Month (1 - 12 or JAN - DEC)
│ │ │ │ ┌───────────── Day of Week (0 - 6 or SUN - SAT)
│ │ │ │ │

  • * * * * command_to_execute

Understanding Special Characters

  • (Asterisk / Wildcard): Matches every possible value in the field (e.g., every minute). , (Comma / List): Specifies a discrete list of values (e.g., 1,15,30).
  • (Hyphen / Range): Defines an inclusive range of values (e.g., 9-17 for 9am through 5pm). / (Slash / Step): Specifies increments (e.g., */15 in the minute field means every 15 minutes).

Common Examples in Production

Expression Plain English Meaning
0 0 * * * Every midnight (00:00)
*/15 * * * * Every 15 minutes
0 9-17 * * 1-5 Every hour from 9am to 5pm, Monday to Friday
Need to test or verify a complex cron string before deploying to production? Use our interactive Cron Expression Parser to see exact upcoming execution times in your local timezone.

Top comments (0)