root/learning-hub/devops-cloud/cron-expression-cheat-sheet
← Back to Learning Hub
DEVOPS & CLOUDCHEAT SHEET•5 min read•Beginner••100% Client-Side Verified

Cron Expression Cheat Sheet — Complete Syntax, Examples & Schedule Guide

The ultimate reference guide to cron expression syntax. Covers 5-field & 6-field formats, special characters (*, /, -, ,), common schedules, and real-world examples.

#Cron#Linux#Kubernetes#DevOps#Crontab#Scheduling

Interactive Cron Schedule Visualizer

Live Interactive Sandbox
100% Client-Side

Runs every 15 minutes between 9:00 AM and 5:59 PM, Monday through Friday. Test the preset input below or customize it before launching into the full workspace.

Cron Expression:
Ready for advanced parsing, syntax error highlighting & bulk export?
Open in Full Workspace (Cron Visualizer)

Cron is a time-based job scheduling daemon standard on Unix-like operating systems (Linux, macOS, BSD) and widely adopted across modern cloud systems like Kubernetes CronJobs, AWS CloudWatch Events, GitHub Actions, and Google Cloud Scheduler.

This cheat sheet provides a complete reference for cron syntax, special characters, predefined macros, copy-paste production schedules, and troubleshooting tips.


The 5-Field Standard Cron Syntax

A traditional cron schedule consists of five fields separated by whitespace:

┌───────────── 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) (Sunday = 0 or 7)
│ │ │ │ │
* * * * * <command-to-execute>

Field Descriptions & Allowed Ranges

Field Description Allowed Values Allowed Special Characters
Minute Minute of the hour 0 - 59 * , - /
Hour Hour of the day (24-hour) 0 - 23 * , - /
Day of Month Calendar day of the month 1 - 31 * , - / L W
Month Month of the year 1 - 12 or JAN-DEC * , - /
Day of Week Day of the week 0 - 7 (0/7=Sun) or SUN-SAT * , - / L #

Note on Sunday: In standard Unix cron, both 0 and 7 represent Sunday.


Special Operators Explained

Cron uses specific operators to represent intervals, lists, and wildcards:

1. Asterisk (*) — Every Value

Represents all possible values for that field.

  • * * * * * = Every minute of every hour of every day.

2. Comma (,) — List of Values

Specifies multiple distinct values for a field.

  • 0 9,12,15 * * * = At minute 0 of hours 9, 12, and 15 (9:00 AM, 12:00 PM, 3:00 PM every day).

3. Hyphen (-) — Range of Values

Defines an inclusive continuous range.

  • 0 9-17 * * 1-5 = Every hour on the hour from 9:00 AM through 5:00 PM, Monday through Friday.

4. Slash (/) — Step / Interval Values

Specifies step increments through a range.

  • */15 * * * * = Every 15 minutes (0, 15, 30, 45).
  • 0 0-12/2 * * * = Every 2 hours starting from midnight until noon (0:00, 2:00, 4:00, ..., 12:00).

Quick Reference: Common Cron Patterns

Copy and paste these verified cron schedules directly into your configuration:

Schedule Requirement Cron Expression Plain English Breakdown
Every minute * * * * * Every minute
Every 5 minutes */5 * * * * At every 5th minute
Every 15 minutes */15 * * * * At minutes 0, 15, 30, and 45
Every 30 minutes */30 * * * * At minutes 0 and 30
Every hour on the hour 0 * * * * At minute 0 of every hour
Every 2 hours 0 */2 * * * At minute 0 of every 2nd hour
Every day at midnight 0 0 * * * At 00:00 (12:00 AM) every day
Every day at 3:30 AM 30 3 * * * At 03:30 (3:30 AM) every day
Every weekday (Mon-Fri) at 9 AM 0 9 * * 1-5 At 09:00 on Monday through Friday
Every weekend (Sat-Sun) at midnight 0 0 * * 6,0 At 00:00 on Saturday and Sunday
Every Sunday at 4:00 AM 0 4 * * 0 At 04:00 on Sunday
1st day of every month at midnight 0 0 1 * * At 00:00 on day 1 of every month
Every quarter (Jan, Apr, Jul, Oct 1st) 0 0 1 1,4,7,10 * At 00:00 on the 1st of every 3rd month
Once a year (Jan 1st at midnight) 0 0 1 1 * At 00:00 on January 1st

Predefined Special Macros

Many modern cron implementations (such as Vixie Cron and crontab) support convenient shortcut macros instead of the 5-field syntax:

Macro Equivalent 5-Field Syntax Description
@yearly / @annually 0 0 1 1 * Run once a year at midnight of January 1st
@monthly 0 0 1 * * Run once a month at midnight of the 1st day
@weekly 0 0 * * 0 Run once a week at midnight on Sunday
@daily / @midnight 0 0 * * * Run once a day at midnight (00:00)
@hourly 0 * * * * Run once an hour at the beginning of the hour
@reboot N/A Run once automatically at system startup

Real-World Production Crontab Examples

1. PostgreSQL / MySQL Daily Backup

Run a database backup dump every night at 2:15 AM and redirect logs:

15 2 * * * /usr/local/bin/pg_dump -U postgres my_db > /var/backups/db_$(date +\%Y\%m\%d).sql 2>&1

2. Log Rotation & Cache Cleanup

Purge temporary files and rotate server logs every Sunday at 3:00 AM:

0 3 * * 0 /usr/sbin/logrotate /etc/logrotate.conf && find /tmp -type f -mtime +7 -delete

3. SSL Certificate Auto-Renewal (Certbot)

Attempt Let's Encrypt renewal twice daily at random minute offsets:

0 0,12 * * * /usr/bin/certbot renew --quiet

4. Health Check / Uptime Ping

Trigger an internal API health ping every 5 minutes:

*/5 * * * * /usr/bin/curl -fsS https://api.example.com/health > /dev/null

Troubleshooting & Best Practices

  1. Always Use Absolute Binary Paths: Cron executes in a very minimal shell environment with a stripped down $PATH. Instead of typing python3 script.py, always write /usr/bin/python3 /opt/app/script.py.
  2. Account for Timezones: Cron runs against the system clock (typically UTC in cloud environments like AWS EC2, GCP, and Kubernetes). Ensure your schedule accounts for UTC vs your local time.
  3. Capture stdout and stderr: By default, cron attempts to email output to the user. Always redirect output to log files or null:
    0 4 * * * /path/to/job.sh >> /var/log/job.log 2>&1
    
  4. Escape the % Character in Crontab: The percent sign (%) in crontab entries is treated as a newline unless escaped with a backslash (\%).

Live Tool: Cron Expression Visualizer

Client-Side Engine

Translates complex cron schedules into plain English with a 5-column breakdown grid.

Launch Tool Workspace

Frequently Asked Questions (FAQ)

It means 'run every 5 minutes' (at minutes 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, and 55 of every hour).

Related Guides & References

view learning hub →