Cron Expression Guide: Master Linux Task Scheduling

Learn how to write, understand, and debug cron expressions. Includes a visual builder and common examples for developers.

Cron Expression Guide: Master Linux Task Scheduling

What is Cron?

Cron is a time-based job scheduler in Unix-like operating systems. It allows you to automate repetitive tasks — backups, log rotation, report generation — all without manual intervention. If you write software that needs to run on a schedule, understanding cron is essential.

Cron Expression Format

A cron expression consists of five fields, separated by spaces:

* * * * *
│ │ │ │ │
│ │ │ │ └── Day of week (0–7, Sunday = 0 or 7)
│ │ │ └──── Month (1–12)
│ │ └────── Day of month (1–31)
│ └──────── Hour (0–23)
└────────── Minute (0–59)

Special Characters

  • * — any value (matches everything)
  • , — value list separator (e.g., 1,15 = 1st and 15th)
  • - — range (e.g., 9-17 = 9am to 5pm)
  • / — step (e.g., */15 = every 15 minutes)

Common Examples

# Every minute
* * * * *

# Every hour (at minute 0)
0 * * * *

# Every day at midnight
0 0 * * *

# Every Monday at 9am
0 9 * * 1

# Every 15 minutes
*/15 * * * *

# Every day at 2:30am
30 2 * * *

# First day of every month at midnight
0 0 1 * *

# Every 6 hours
0 */6 * * *

Using Our Cron Generator

Our Cron Generator lets you build cron expressions visually. Choose your schedule from dropdowns, preview the next run times, and copy the expression — no memorization needed.

Tips

  • Always test cron jobs in a staging environment first
  • Use absolute paths in scripts (cron runs with a minimal PATH)
  • Redirect output to log files: 0 * * * * /script.sh >> /var/log/script.log 2>&1
  • Check system crontab with crontab -l

Quartz Format (Java)

If you work with Java/Spring, you may encounter Quartz-format cron expressions, which add a seconds field. Our generator supports both standard Unix cron and Quartz formats.

← Back to Blog
Copied!