What is a Cron Expression?
A cron expression is a compact, text-based syntax used to define recurring schedules for automated tasks. Originating from the Unix operating system, cron is the standard tool for scheduling background jobs — from database backups and log rotations to sending emails and triggering API calls. The name comes from the Greek word chronos, meaning time.
A standard cron expression consists of five fields separated by spaces, each representing a time unit. The fields are: minute, hour, day of month, month, and day of week. By combining values, wildcards, and special characters in these five fields, you can express almost any recurring time pattern — from "every minute" to "at 3:15 AM on the 15th of every quarter, but only on Tuesdays."
Cron Field Reference
| Field | Position | Allowed Values | Special Characters |
|---|---|---|---|
| Minute | 1st | 0–59 | * , - / |
| Hour | 2nd | 0–23 | * , - / |
| Day of Month | 3rd | 1–31 | * , - / ? |
| Month | 4th | 1–12 | * , - / |
| Day of Week | 5th | 0–6 (0=Sun) | * , - / ? |
Special character meanings:
*— Any value. In the minute field,*means every minute (0, 1, 2, … 59)./— Step values.*/5means every 5 units.2/3means starting at 2, every 3 units.-— Range.1-5means 1, 2, 3, 4, 5.,— List.1,3,5means 1 or 3 or 5.
Common Cron Expression Examples
| Expression | Description |
|---|---|
| * * * * * | Every minute |
| 0 * * * * | Every hour at minute 0 |
| */5 * * * * | Every 5 minutes |
| 0 0 * * * | Every day at midnight (00:00) |
| 0 9 * * 1-5 | Weekdays at 9:00 AM |
| 0 0 1 * * | First day of every month at midnight |
| 0 0 * * 0 | Every Sunday at midnight |
| 0 6 * * 1 | Every Monday at 6:00 AM |
| 0 0 1 1 * | January 1st at midnight (yearly) |
| 30 23 * * * | Every day at 11:30 PM |
How to Use Cron on Linux and Mac
On Linux and macOS, cron jobs are managed via the crontab command. Each user has their own crontab file — a list of cron expressions paired with commands to run.
Common crontab commands:
crontab -e— Edit your crontab (opens in your default editor)crontab -l— List your current cron jobscrontab -r— Remove your entire crontab (use with caution)
Crontab entry format:
minute hour day-of-month month day-of-week /path/to/command
Example entry that runs a backup script every day at 2:30 AM:
30 2 * * * /home/user/scripts/backup.sh
To ensure commands run reliably from cron, always use absolute paths. Cron runs in a minimal environment and does not load your shell profile, so commands like node, python, or php may not be found unless you specify the full path (e.g., /usr/local/bin/node). Redirect output to a log file with >> /var/log/myjob.log 2>&1 to capture both stdout and stderr for debugging.
Also consider tools like related Unix Timestamp Converter when working with time-based scheduling. For generating unique job identifiers, see the UUID Generator. If you need to hash output from your cron scripts, check out the Hash Generator.
Frequently Asked Questions
What is a cron expression?
A cron expression is a string of five whitespace-separated fields that defines a recurring schedule for automated tasks. The fields represent minute (0–59), hour (0–23), day of month (1–31), month (1–12), and day of week (0–6, where 0 is Sunday). Special characters like * (every), / (step), - (range), and , (list) allow flexible patterns. Cron jobs are programs or scripts executed by the Unix cron daemon at the specified schedule.
What does */5 mean in a cron expression?
The */5 notation means "every 5 units." In the minute field, */5 means every 5 minutes (at minutes 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55). The * means "start from 0" and /5 means "step by 5." You can also write 0/5 for the same result. In the hour field, */2 would mean every 2 hours (0:00, 2:00, 4:00, …).
What is the difference between 0 5 * * * and */5 * * * *?
0 5 * * * means "at 5:00 AM every day" — it fires once per day. The 0 is the minute field and 5 is the hour field, so it runs at exactly 05:00. In contrast, */5 * * * * means "every 5 minutes, continuously" — it fires 12 times per hour, 288 times per day. These are completely different schedules; confusing them is one of the most common cron mistakes.
How do I run a cron job every weekday at 9 AM?
Use the expression 0 9 * * 1-5. The fields mean: at minute 0, at hour 9 (9 AM), any day of month, any month, Monday through Friday (1–5). This runs the job at 9:00 AM sharp on Monday, Tuesday, Wednesday, Thursday, and Friday. To also run on Saturday, use 1-6 in the day-of-week field. Note that the day-of-week field uses 1=Monday and 6=Saturday in standard Unix cron.
Are cron expressions the same in all tools?
Standard Unix cron uses 5 fields (minute, hour, day-of-month, month, day-of-week). However, several platforms extend this: Quartz Scheduler and Spring Framework use 6 fields (adding a seconds field at the start) or 7 fields (also adding a year at the end). AWS EventBridge (CloudWatch Events) uses 6 fields with different syntax for year. GitHub Actions uses standard 5-field cron. Always check the documentation of the specific platform you are targeting. This generator produces standard 5-field Unix cron expressions compatible with Linux crontab, macOS, and most CI/CD systems.