Irreva logo
Explore Irreva
DeveloperMarch 11, 2026· 6 min read· Updated June 10, 2026

What Is Cron Job Syntax and How to Write It

Hasanur Rahman

Written by Hasanur Rahman

Founder & Full-Stack Developer · Irreva · Rangpur, Bangladesh

Cron is the standard tool for scheduling recurring tasks on Unix-like systems. A cron job runs a command at a specified time or interval — every night at midnight, every Monday at 9am, every 15 minutes. The schedule is defined by a cron expression: five space-separated fields that look cryptic until you understand them. This guide explains every part of the syntax.

The five fields of a cron expression

A cron expression has five fields: minute, hour, day of month, month, and day of week. The expression '0 9 * * 1' runs at 9:00 AM every Monday. Each field specifies when the task should run in that time unit, and * means 'every' for that field.

Fields are read left to right. Minutes are 0–59, hours are 0–23, day of month is 1–31, month is 1–12 (or JAN–DEC), and day of week is 0–7 where both 0 and 7 represent Sunday (or SUN–SAT).

The format is: ┌───── minute (0–59) ┬───── hour (0–23) ┬───── day of month (1–31) ┬───── month (1–12) ┬───── day of week (0–7). Fields are read in that order.

  • * — every value (every minute, every hour, etc.)
  • , — list (1,3,5 means 1, 3, and 5)
  • - — range (1-5 means 1 through 5)
  • / — step (*/5 means every 5, starting from 0)
  • ? — no specific value (used for day fields in some implementations)

Common cron expressions with explanations

Learning cron expressions is easiest through examples. Here are the most common schedules and how to write them.

'0 0 * * *' — midnight every day. '0 * * * *' — at the start of every hour. '*/15 * * * *' — every 15 minutes. '0 9 * * 1-5' — 9am Monday through Friday. '0 0 1 * *' — midnight on the first day of every month. '0 0 * * 0' — midnight every Sunday.

The step notation (/) is particularly useful. '*/5 * * * *' means every 5 minutes. '0 */2 * * *' means every 2 hours on the hour. '0 9-17 * * 1-5' means every hour from 9am to 5pm on weekdays.

  • 0 0 * * * — every day at midnight
  • 0 * * * * — every hour
  • */15 * * * * — every 15 minutes
  • 0 9 * * 1-5 — 9am weekdays
  • 0 0 1 * * — first of every month at midnight
  • 0 0 * * 0 — every Sunday at midnight
  • 30 18 * * 1,3,5 — 6:30pm on Monday, Wednesday, Friday

Special strings and extensions

Many cron implementations support predefined special strings as shortcuts: @hourly (0 * * * *), @daily (0 0 * * *), @weekly (0 0 * * 0), @monthly (0 0 1 * *), @yearly (0 0 1 1 *), and @reboot (runs once at startup).

Some cloud schedulers (AWS EventBridge, GitHub Actions) use cron with a sixth field for seconds, or a different field order. AWS EventBridge, for example, uses six fields: minute, hour, day-of-month, month, day-of-week, year. Always check the documentation for the specific scheduler you're using.

Crontab files also include the command to run after the five fields: '0 0 * * * /usr/bin/backup.sh'. You can also set environment variables at the top of the crontab file.

Testing and debugging cron expressions

The best way to verify a cron expression is to check when it will next fire. Online cron expression testers show the next N execution times for any expression, which immediately reveals whether it does what you intend.

Common mistakes: forgetting that day-of-week and day-of-month combine with OR logic (if both are set to specific values, the job runs when either condition is true, not both). Using 0 for both Sunday and day-of-week position 0, which is fine. Forgetting that months are 1-indexed while minutes and hours start at 0.

For server cron jobs, check that the server's timezone is what you expect. Cron uses the system timezone by default. A job scheduled at 9am UTC runs at a different local time depending on where you are.

Frequently Asked Questions

How do I edit cron jobs on a Linux server?

Use 'crontab -e' to edit your user's cron jobs, or 'sudo crontab -e' for root jobs. This opens your crontab in the default editor. Add one cron expression per line. Save and exit to install the new schedule.

How can I check if a cron job ran?

Cron typically logs output to syslog. On most Linux systems, check /var/log/syslog or /var/log/cron. Redirect the command's output to a log file in the cron job: '0 0 * * * /path/to/script.sh >> /var/log/myjob.log 2>&1'.

What's the smallest interval I can run a cron job?

Standard cron has a minimum interval of one minute. If you need sub-minute scheduling, use a different tool — a systemd timer with an AccuracySec setting, a job queue, or a sleep loop in a long-running process.

Does the cron job run if the server is off?

No. Cron only runs scheduled jobs if the system is running at the scheduled time. If your server is off at midnight, the midnight job won't run when the server starts. Use anacron for jobs that should run on the next startup if they were missed.

What is the difference between cron and a task queue?

Cron is for time-based scheduled execution. A task queue (like Celery, Sidekiq, or BullMQ) is for running tasks asynchronously in response to application events, with retry logic, priority, and concurrency control. Many applications use both: cron to enqueue tasks and a queue to execute them reliably.

Hasanur Rahman

About the author

Hasanur Rahman

Founder & Full-Stack Developer · Irreva · Rangpur, Bangladesh

Hasanur Rahman is the founder of Irreva and a full-stack developer based in Rangpur, Bangladesh. He builds all of Irreva's tools with a focus on privacy-first, browser-based processing.