Task scheduling is the backbone of automation. Whether you are running nightly backups, sending daily reports, pruning old logs every Sunday, or triggering a webhook every 15 minutes — cron is the tool that makes it happen. But cron expressions have a reputation for being cryptic and hard to remember. This guide changes that.
We will break down every field, provide real-world examples you can copy and paste, and show you how to use Risetop's visual cron expression generator to build schedules without memorizing syntax.
What Is a Cron Expression?
A cron expression is a string of five (or more) fields separated by spaces that defines a schedule. Each field represents a unit of time. The cron daemon (cron or crond) reads these expressions and executes commands at the specified times.
Here is the standard five-field format used on Linux and macOS:
* * * * *
│ │ │ │ │
│ │ │ │ └── Day of week (0-7, 0 and 7 = Sunday)
│ │ │ └──── Month (1-12)
│ │ └────── Day of month (1-31)
│ └──────── Hour (0-23)
└────────── Minute (0-59)
For example, 30 14 * * 5 means "run at 2:30 PM every Friday." Simple once you know the pattern, but the range of possible combinations is vast.
Cron Syntax Reference
Each field accepts several special characters that give you precise control over scheduling:
| Symbol | Meaning | Example | Result |
* | Any value (every) | * * * * * | Every minute |
, | List separator | 0 9,18 * * * | 9 AM and 6 PM daily |
- | Range | 0 9-17 * * * | Every hour 9 AM–5 PM |
/ | Step values | */15 * * * * | Every 15 minutes |
L | Last day | 0 0 L * * | Last day of month at midnight |
W | Nearest weekday | 0 0 15W * * | Nearest weekday to the 15th |
# | Nth day of month | 0 0 * * 6#2 | Second Saturday of month |
Note: The L, W, and # operators are not supported in standard Linux cron. They are specific to frameworks like Quartz (Java) and Spring. Standard cron uses only *, ,, -, and /.
Common Cron Expression Examples
Here are the most frequently needed cron schedules, ready to copy and use:
| Schedule | Expression |
| Every minute | * * * * * |
| Every 5 minutes | */5 * * * * |
| Every hour | 0 * * * * |
| Every day at midnight | 0 0 * * * |
| Every day at 6:30 AM | 30 6 * * * |
| Every Monday at 9 AM | 0 9 * * 1 |
| Weekdays at 9 AM | 0 9 * * 1-5 |
| First of every month | 0 0 1 * * |
| Every 3 hours | 0 */3 * * * |
| Twice a day (6 AM and 6 PM) | 0 6,18 * * * |
| Last day of month at midnight | 0 0 28-31 * * [ $(date -d '+1 day' +%d) -eq 01 ] && command |
| Every Sunday at noon | 0 12 * * 0 |
Extended Cron (6 and 7 Fields)
Frameworks like Quartz (Java), Spring Boot, and AWS EventBridge use extended cron with additional fields:
0 0 12 * * ? * ← Quartz (seconds, min, hour, day, month, weekday, year)
└──└──└───└──└───└──└──
s m h DM M DW Y
The key difference: Quartz adds a seconds field at the beginning and supports the ? operator (meaning "no specific value"). This is important because Quartz does not allow both day-of-month and day-of-week to be specified simultaneously — you must use ? for one of them.
For example, 0 0/30 9-17 ? * MON-FRI means "every 30 minutes between 9 AM and 5 PM, Monday through Friday" in Quartz syntax.
How to Use the Cron Expression Generator
Instead of writing expressions from scratch, you can use Risetop's Cron Expression Generator to build them visually:
- Choose your schedule type — every minute, hourly, daily, weekly, monthly, or custom.
- Set the values — pick specific minutes, hours, days, or months from dropdown menus.
- Preview execution times — the tool shows you the next 10 scheduled run times so you can verify accuracy.
- Copy the expression — one click copies the cron expression to your clipboard, ready to paste into crontab, a CI/CD pipeline, or a cloud scheduler.
This eliminates the guesswork and lets you build complex schedules in seconds.
Setting Up Cron Jobs
Linux / macOS
# Edit your crontab
crontab -e
# View existing jobs
crontab -l
# Example: backup database every day at 2 AM
0 2 * * * /usr/bin/pg_dump mydb > /backups/mydb_$(date +\%Y\%m\%d).sql
# Example: clear temp files every Sunday at 3 AM
0 3 * * 0 find /tmp -type f -mtime +7 -delete
# Example: health check every 5 minutes
*/5 * * * * curl -sf https://api.example.com/health || echo "DOWN" | mail -s "Alert" admin@example.com
Special Environment Variables
# Set PATH at the top of your crontab
PATH=/usr/local/bin:/usr/bin:/bin
SHELL=/bin/bash
# Log output to a file
0 * * * * /home/user/script.sh >> /var/log/myjob.log 2>&1
Common pitfall: Cron runs with a minimal environment — it does not load your .bashrc or .profile. Always use absolute paths to scripts and executables, or set the PATH explicitly at the top of your crontab.
Cloud Platforms
- AWS CloudWatch Events / EventBridge: Uses rate expressions (
rate(5 minutes)) or cron expressions with 6 fields (year is optional).
- Google Cloud Scheduler: Accepts standard cron with an optional seconds field. Timezone is configurable.
- GitHub Actions: Uses cron in workflow YAML:
on: schedule: - cron: '0 9 * * 1-5' (UTC by default).
- Kubernetes CronJob: Standard 5-field cron in the manifest:
schedule: "0 2 * * *".
Real-World Use Cases
Automated Backups
Schedule database backups, file snapshots, and system images at regular intervals. A daily cron job at 2 AM ensures your data is backed up during low-traffic hours without manual intervention.
Report Generation and Distribution
Generate weekly sales reports every Monday morning and email them to stakeholders. Or create daily analytics summaries and push them to a Slack channel.
System Maintenance
Clean up old log files, rotate certificates, prune Docker images, clear temporary caches, and run disk health checks on a schedule. These housekeeping tasks keep systems running smoothly.
Data Pipeline Scheduling
ETL (Extract, Transform, Load) jobs, data sync between services, and batch processing workflows all rely on cron for timing. Airflow, Prefect, and similar orchestrators use cron expressions under the hood.
Troubleshooting Cron Jobs
- Job not running? Check
grep CRON /var/log/syslog (Linux) or log show --predicate 'process == "cron"' --last 1h (macOS) for errors.
- Script works manually but not in cron? Environment variables are missing. Add
PATH=... to crontab or source your profile in the script.
- Wrong timezone? Cron uses the system timezone by default. Set it explicitly:
CRON_TZ=America/New_York.
- Silent failures? Always redirect output:
command >> /path/to/log 2>&1.
Frequently Asked Questions
What does a cron expression look like?
A standard cron expression has five fields: minute, hour, day of month, month, and day of week. For example, "0 9 * * 1-5" means 9:00 AM every Monday through Friday. Extended cron (used by Quartz, Spring) has 6-7 fields, adding seconds and optionally years.
How do I schedule a cron job to run every 5 minutes?
Use the expression */5 * * * *. The */5 syntax means "every 5th value" in the minute field, so the job runs at minutes 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, and 55.
What is the difference between * and ? in cron?
In standard Linux cron, * means "every possible value" and there is no ? operator. In extended cron (Quartz, Spring), ? means "no specific value" and is used in the day-of-month or day-of-week field to indicate that field should be ignored when the other is specified.
Can I test a cron expression before deploying it?
Yes. Use Risetop's Cron Expression Generator tool to visually build and test cron expressions. It shows you the next 10 execution times so you can verify your schedule is correct before putting it into production.
How do I view or edit my existing cron jobs?
On Linux/macOS, run crontab -l to list your current cron jobs and crontab -e to edit them. Each line is one cron job in the format: expression command. Always test with crontab -l after editing to confirm your changes were saved.
Related Tools
Build Cron Expressions Visually
No more guessing. Our visual generator lets you pick, preview, and copy cron expressions in seconds.
Open Cron Generator →