DevOps

Cron Job Syntax: The Complete Guide with Examples

πŸ“… June 6, 2026⏱ 7 min read πŸ› οΈ Try the Cron Builder β†’

Cron syntax is something every developer looks up every single time. This guide explains every field, special character and common schedule β€” so you never have to Google it again.

What Is a Cron Job?

A cron job is a scheduled task that runs automatically at specified times on Unix/Linux systems. The name comes from Chronos (Greek god of time). Cron jobs are used for:

πŸ‘‰ Don't want to memorize the syntax? Use our free Cron Builder β€” build expressions visually and see exactly when your job will run next.

Cron Expression Structure

A cron expression has 5 fields separated by spaces:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ minute (0–59)
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ hour (0–23)
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ day of month (1–31)
β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ month (1–12)
β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ day of week (0–6, Sunday=0)
β”‚ β”‚ β”‚ β”‚ β”‚
* * * * *  command to execute
FieldRangeSpecial characters
Minute0–59* , - /
Hour0–23* , - /
Day of month1–31* , - / ? L W
Month1–12 or JAN–DEC* , - /
Day of week0–6 or SUN–SAT* , - / ? L #

Special Characters Explained

* β€” Asterisk (every value)

# Run every minute
* * * * *

# Run every hour at minute 0
0 * * * *

, β€” Comma (list of values)

# Run at 9 AM and 5 PM every day
0 9,17 * * *

# Run on Monday, Wednesday and Friday
0 9 * * 1,3,5

- β€” Hyphen (range of values)

# Run every hour from 9 AM to 5 PM
0 9-17 * * *

# Run Monday through Friday at 8 AM
0 8 * * 1-5

/ β€” Slash (step values)

# Run every 15 minutes
*/15 * * * *

# Run every 6 hours
0 */6 * * *

# Run every 2 days
0 0 */2 * *

? β€” Question mark (no specific value β€” day fields only)

# Run on the 15th of every month, any day of week
0 0 15 * ?

# Run every Monday, any day of month
0 0 ? * 1

L β€” Last (last day of month or week)

# Run on the last day of every month
0 0 L * *

# Run on the last Friday of every month
0 0 ? * 5L

Most Common Cron Schedules

ExpressionMeaning
* * * * *Every minute
*/5 * * * *Every 5 minutes
*/15 * * * *Every 15 minutes
*/30 * * * *Every 30 minutes
0 * * * *Every hour (at :00)
0 */2 * * *Every 2 hours
0 0 * * *Every day at midnight
0 9 * * *Every day at 9 AM
0 9 * * 1-5Weekdays at 9 AM
0 0 * * 0Every Sunday at midnight
0 0 1 * *First day of every month
0 0 L * *Last day of every month
0 0 1 1 *Every year on January 1st
0 9,17 * * 1-5Weekdays at 9 AM and 5 PM
0 0 * * 1Every Monday at midnight

Cron Shorthand Strings

Most cron implementations support these convenient shortcuts:

ShorthandEquivalentMeaning
@yearly0 0 1 1 *Once a year, January 1st
@monthly0 0 1 * *Once a month, first day
@weekly0 0 * * 0Once a week, Sunday midnight
@daily0 0 * * *Once a day, midnight
@hourly0 * * * *Once an hour
@rebootN/AOnce at startup

Real-World Cron Job Examples

Database backup every night at 2 AM:

0 2 * * * /usr/bin/mysqldump -u root mydb > /backups/db-$(date +%Y%m%d).sql

Clear temp files every Sunday at 3 AM:

0 3 * * 0 rm -rf /tmp/myapp/*

Send weekly report every Monday at 9 AM:

0 9 * * 1 /usr/bin/python3 /scripts/weekly-report.py

Check server health every 5 minutes:

*/5 * * * * /scripts/health-check.sh >> /var/log/health.log 2>&1

Renew SSL certificate on the 1st of every month:

0 0 1 * * certbot renew --quiet

Run a Node.js script every weekday at 8 AM:

0 8 * * 1-5 cd /app && /usr/bin/node /app/scripts/daily-sync.js

How to Edit Crontab

# Open crontab editor
crontab -e

# List all cron jobs for current user
crontab -l

# Remove all cron jobs
crontab -r

# Edit crontab for a specific user (root only)
crontab -u username -e

Cron Job Logging

By default cron sends output to your email. To redirect output to a log file:

# Redirect stdout and stderr to a log file
*/30 * * * * /scripts/my-script.sh >> /var/log/my-script.log 2>&1

# Suppress all output (silent)
*/30 * * * * /scripts/my-script.sh > /dev/null 2>&1

# Log with timestamp
*/30 * * * * echo "$(date): running" >> /var/log/my-script.log && /scripts/my-script.sh >> /var/log/my-script.log 2>&1

Common Cron Mistakes to Avoid

Set PATH in Crontab

# Add this at the top of your crontab
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Then your jobs
0 2 * * * backup.sh

Cron vs Other Schedulers

SchedulerBest forComplexity
CronSimple recurring tasks on Linux/MacLow
Systemd timersModern Linux systems, more controlMedium
Task SchedulerWindows environmentsLow
Celery BeatPython apps with distributed tasksHigh
node-cronNode.js applicationsLow
QuartzJava applicationsMedium

Frequently Asked Questions

How do I run a cron job every 10 seconds?
Standard cron only goes down to 1 minute. To run every 10 seconds use:

* * * * * /script.sh
* * * * * sleep 10; /script.sh
* * * * * sleep 20; /script.sh
* * * * * sleep 30; /script.sh
* * * * * sleep 40; /script.sh
* * * * * sleep 50; /script.sh

What does */5 mean in cron?
The / means "every" and */5 means "every 5 units". In the minute field, */5 means every 5 minutes (at 0, 5, 10, 15... 55). In the hour field, */5 means every 5 hours.

How do I test a cron expression?
Use our free Cron Builder β€” paste any expression and see the next 10 run times instantly. No guessing required.

Does cron run if the computer is off?
No β€” if the system is off when a job was scheduled, it won't run when it comes back online (unless you use anacron which handles missed jobs).

What is the difference between crontab and cron?
cron is the daemon (background service) that runs scheduled jobs. crontab is the file containing your schedule, and also the command used to edit that file.

How do I run a cron job on weekdays only?

# Run at 9 AM Monday through Friday
0 9 * * 1-5
Build cron expressions visually β€” free & instant

Use our Cron Builder to create and validate cron expressions. See exactly when your job will run next β€” no syntax memorization needed.

Cron Builder β†’