Crontab Expression Generator: Complete Guide with Examples
If you've ever needed to automate a task on a Linux server — whether it's running a backup script, sending email reports, or cleaning up log files — you've probably encountered cron. Cron is one of the most useful tools in a developer's arsenal, but writing cron expressions can feel like trying to read ancient hieroglyphics.
Five fields, special characters, confusing rules about day of month vs day of week... it's easy to get it wrong. And when you get cron wrong, your task either runs at the wrong time or doesn't run at all — which is a problem if it's something important like database backups.
In this complete guide, we'll break down cron expression syntax, explain every special character, and give you 15+ real-world examples you can use immediately.
Quick tip: Always test your cron expressions before relying on them for production tasks. Use a cron expression generator to verify the next 5-10 run times.
What Is Cron?
Cron is a time-based job scheduler in Unix-like operating systems. It lets you schedule commands or scripts to run automatically at specific times, dates, or intervals. The name "cron" comes from the Greek word "chronos," meaning time.
Cron is used for everything from simple tasks (like running a backup at 2 AM) to complex scheduling (like running a script every 15 minutes during business hours on weekdays).
Cron Expression Syntax
A cron expression consists of five fields that represent different units of time:
| Field | Allowed Values | Allowed Special Chars |
|---|---|---|
| Minute | 0-59 | * , - / |
| Hour | 0-23 | * , - / |
| Day of Month | 1-31 | * , - / ? L W |
| Month | 1-12 (or JAN-DEC) | * , - / |
| Day of Week | 0-6 (or SUN-SAT, 0=Sunday) | * , - / ? L # |
Special Characters Explained
Asterisk (*)
The asterisk means "every" — it matches all values in the field. For example, * in the
minute field means "every minute."
Comma (,)
The comma is used to list multiple values. For example, 1,15,30 in the minute field
means "at minutes 1, 15, and 30."
Hyphen (-)
The hyphen defines a range. For example, 9-17 in the hour field means "every hour
from 9 AM to 5 PM" (9, 10, 11, 12, 13, 14, 15, 16, 17).
Slash (/)
The slash defines step values. For example, */15 in the minute field means "every 15 minutes"
(0, 15, 30, 45). You can also use ranges: 0-30/5 means "every 5 minutes from 0 to 30."
Question Mark (?)
The question mark is used in the Day of Month and Day of Week fields to indicate "no specific value." It's used when you want to specify one but not the other (since they can conflict).
L (Last)
The L character means "last." In Day of Month, L means "last day of the month."
In Day of Week, 6L means "last Friday of the month."
W (Weekday)
The W character means "nearest weekday." For example, 15W means "nearest weekday to the 15th."
If the 15th is a Saturday, it runs on Friday the 14th. If it's a Sunday, it runs on Monday the 16th.
Hash (#)
The hash is used in Day of Week to specify "nth" occurrence. For example, 3#2 means
"second Tuesday of the month" (3 = Tuesday, #2 = second occurrence).
15+ Common Cron Expression Examples
Here are the most commonly used cron expressions, explained:
Basic Scheduling
| Cron Expression | What It Does |
|---|---|
* * * * * | Every minute |
0 * * * * | Every hour (at minute 0) |
0 0 * * * | Every day at midnight |
0 12 * * * | Every day at noon |
0 0 * * 0 | Every Sunday at midnight |
0 0 1 * * | First day of every month |
Intervals
| Cron Expression | What It Does |
|---|---|
*/5 * * * * | Every 5 minutes |
*/15 * * * * | Every 15 minutes |
0 */2 * * * | Every 2 hours |
0 */6 * * * | Every 6 hours |
30 */4 * * * | Every 4 hours at 30 minutes past |
Business Hours & Weekdays
| Cron Expression | What It Does |
|---|---|
0 9 * * 1-5 | Weekdays at 9 AM (Mon-Fri) |
0 9-17 * * 1-5 | Every hour 9 AM-5 PM on weekdays |
*/30 9-17 * * 1-5 | Every 30 min during business hours |
0 17 * * 5 | Every Friday at 5 PM |
0 0 * * 6,0 | Weekends at midnight (Sat & Sun) |
Specific Dates & Times
| Cron Expression | What It Does |
|---|---|
0 2 1 * * | 1st of every month at 2 AM |
0 0 1 1 * | January 1st at midnight |
0 12 25 12 * | December 25th at noon |
0 8 1 1,4,7,10 * | First day of each quarter at 8 AM |
Common Cron Mistakes (and How to Avoid Them)
1. Confusing Day of Month and Day of Week
One of the most confusing things about cron is that both Day of Month and Day of Week are used to determine when a job runs. If both are specified (not *), the job runs when EITHER condition is met — not both. This is counterintuitive for many people.
0 12 15 * 5 /path/to/script.sh
2. Forgetting About Time Zones
Cron uses the server's local time zone. If your server is in UTC and you're in New York, a cron job
set for "9 AM" will run at 5 AM Eastern time. Always check your server's time zone with date
or timedatectl.
3. Not Testing First
Never set a cron job and assume it works. Always:
- Test the command manually first
- Use a cron expression generator to verify the schedule
- Set the cron job to run in 5 minutes to test it
- Check the logs to make sure it ran successfully
4. Using Relative Paths
Cron jobs run in a minimal environment, so relative paths often don't work. Always use absolute paths for both the command and any files it references.
0 2 * * * backup.sh
# ✅ Good (absolute path)
0 2 * * * /usr/local/bin/backup.sh
5. Not Redirecting Output
By default, cron sends the output of jobs via email. If you don't want emails (or if email isn't set up), redirect output to a log file or /dev/null.
0 2 * * * /path/to/script.sh >> /var/log/script.log 2>&1
# Discard output completely
0 2 * * * /path/to/script.sh > /dev/null 2>&1
Useful Cron Tips & Tricks
View Your Crontab
Edit Your Crontab
Remove All Cron Jobs
Add Comments to Your Crontab
Always add comments explaining what each cron job does. Future you will thank you.
0 2 * * * /usr/local/bin/db-backup.sh
# Clean up old log files every Sunday at 3 AM
0 3 * * 0 /usr/local/bin/clean-logs.sh
Generate Cron Expressions Easily
Use our free crontab generator to build and test cron expressions visually.
Try Free Crontab Generator →FAQ: Common Questions About Cron
Use */5 * * * *. The */5 in the minute field means "every 5 minutes" (0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55).
Cron is the daemon (background service) that runs scheduled tasks. Crontab (cron table) is the file that contains the list of tasks to run, and also the command you use to edit that file.
Common reasons: wrong path to the command, wrong permissions on the script, wrong time zone, environment variables not set, or the script has errors. Check syslog (/var/log/syslog or /var/log/cron) for error messages.
No, cron's smallest unit is minutes. If you need something to run more frequently than every minute, you'll need a different approach — like a background process with a sleep loop, or a tool like systemd timers.
There's no built-in "last day" in standard cron, but you can use a trick: run the script on the 31st and check if tomorrow is the 1st. Or use the L character if your cron implementation supports it (like Quartz or some extended cron daemons).
Final Thoughts
Cron expressions don't have to be intimidating. Once you understand the five fields and what each special character does, it's just a matter of putting the pieces together. And with a good cron expression generator, you can verify your schedule before you set it — no more guessing.
The most important thing is to always test your cron jobs. Don't just set it and forget it — verify that it runs when you expect it to, and that it does what you expect it to do. A few minutes of testing can save you hours of debugging later.
Ready to create your next cron expression? Try our free crontab generator — build your schedule visually and see the next run times instantly.