Copynix
Dev Tools7 min read

Cron Expressions Explained: The Complete Guide to Task Scheduling

Cron syntax looks intimidating at first. This guide breaks down every field, special character, and common pattern so you can confidently schedule tasks in Linux, Docker, Kubernetes, and cloud schedulers.

T

Nguyễn Văn Thương

Founder, Copynix

cronschedulingLinux

What Is Cron?

Cron is a time-based job scheduler in Unix-like operating systems. It runs commands or scripts at specified intervals — hourly, daily, weekly, or on a custom schedule. The schedule is defined using a cron expression: a compact string of five or six fields that specify when the job should run.

Beyond Linux cron, the same expression format is used by GitHub Actions, AWS CloudWatch Events, Kubernetes CronJobs, Heroku Scheduler, and most cloud task scheduling services.

Cron Expression Syntax

A standard cron expression has five fields representing time units:

┌───────── minute (0–59)
│ ┌─────── hour (0–23)
│ │ ┌───── day of month (1–31)
│ │ │ ┌─── month (1–12 or JAN–DEC)
│ │ │ │ ┌─ day of week (0–7, where 0 and 7 = Sunday, or SUN–SAT)
│ │ │ │ │
* * * * *  command

Some systems (Spring, Quartz, AWS) add a sixth field for seconds at the beginning: second minute hour day month weekday.

Special Characters

CharacterMeaningExample
*Every value* * * * * — every minute
,List of values0 9,17 * * * — at 9:00 AM and 5:00 PM
-Range of values0 9-17 * * * — every hour from 9 AM to 5 PM
/Step value*/15 * * * * — every 15 minutes
LLast (some systems)0 0 L * * — last day of each month
WNearest weekday (some systems)0 0 15W * * — nearest weekday to the 15th
#Nth occurrence (some systems)0 0 * * 2#1 — first Monday of month

Common Cron Expressions

# Every minute
* * * * *

# Every 5 minutes
*/5 * * * *

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

# Every day at midnight
0 0 * * *

# Every day at 9:30 AM
30 9 * * *

# Every weekday (Monday–Friday) at 8 AM
0 8 * * 1-5

# Every Monday at 9 AM
0 9 * * 1

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

# Every quarter (Jan, Apr, Jul, Oct) on the 1st at noon
0 12 1 1,4,7,10 *

# Every Sunday at 2 AM (common for maintenance windows)
0 2 * * 0

# Every 30 minutes during business hours (9 AM to 5 PM), weekdays
*/30 9-17 * * 1-5

Special Strings (Linux cron)

Linux cron supports shorthand strings as alternatives to five-field expressions:

StringEquivalentMeaning
@rebootRun once at startup
@yearly0 0 1 1 *Once a year (Jan 1)
@monthly0 0 1 * *Once a month (1st day)
@weekly0 0 * * 0Once a week (Sunday)
@daily0 0 * * *Once a day (midnight)
@hourly0 * * * *Once an hour

Timezone Considerations

Cron jobs run in the server's local timezone by default. This creates problems when:

Best practice: Always set cron jobs in UTC and handle timezone conversion in your application code. Most cloud schedulers (AWS EventBridge, Google Cloud Scheduler) allow you to specify a timezone explicitly.

# Linux — set timezone per cron job (GNU cron extension)
CRON_TZ=America/New_York
0 9 * * 1-5 /path/to/script.sh

Cron in Modern Infrastructure

Kubernetes CronJob

apiVersion: batch/v1
kind: CronJob
metadata:
  name: daily-cleanup
spec:
  schedule: "0 2 * * *"  # 2 AM UTC daily
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cleanup
            image: my-app:latest
            command: ["python", "cleanup.py"]

GitHub Actions

on:
  schedule:
    - cron: "0 6 * * 1"  # Every Monday at 6 AM UTC

Common Pitfalls

Test Your Cron Expressions

Use the Copynix Cron Expression Builder to build and validate cron expressions interactively. See the human-readable schedule description and the next 5 execution times — no configuration needed, runs entirely in your browser.

Summary

Cron expressions are a five-field time specification covering minute, hour, day-of-month, month, and day-of-week. Master the special characters (*, /, -, ,) and you can express almost any schedule. Always use UTC in production, use absolute paths in cron scripts, and implement locking for long-running jobs.

Free tool

Try it yourself — Cron Expression Builder

Runs entirely in your browser. No signup, no data sent to servers.

Open Cron Expression Builder
T

Nguyễn Văn Thương

Founder & Developer · Copynix

Software developer focused on web security and developer tooling. Built Copynix to provide privacy-respecting browser tools that never send your data to a server.

More about the author →

Keep Reading

All articles →
All articlesBrowse tools →