Cron Jobs Explained: A Beginner's Guide to Task Scheduling

Dev Tools March 8, 2026 8 min read

Cron is one of the most useful utilities in Unix-like systems. It lets you schedule tasks (called "cron jobs") to run automatically at specific times — whether that's backing up a database every night, sending a weekly report, or clearing temporary files every hour. This guide will take you from zero to confidently writing cron expressions.

The Five-Field Format

A cron expression consists of five fields separated by spaces, each representing a unit of time:

┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-7, 0 and 7 = Sunday)
│ │ │ │ │
* * * * *

Each field can contain:

Common Cron Schedules

ExpressionSchedule
* * * * *Every minute
*/5 * * * *Every 5 minutes
0 * * * *Every hour (at minute 0)
0 0 * * *Every day at midnight
0 9 * * *Every day at 9:00 AM
0 9 * * 1Every Monday at 9:00 AM
0 0 1 * *First day of every month at midnight
0 0 * * 0Every Sunday at midnight
30 2 * * *Every day at 2:30 AM
0 9-17 * * 1-5Every hour from 9 AM to 5 PM, weekdays only
0 0 1,15 * *1st and 15th of every month at midnight

Special Strings

Many cron implementations support shorthand strings:

Working with Crontab

On Linux/macOS, you manage cron jobs through the crontab (cron table) file:

# View your current cron jobs
crontab -l

# Edit your cron jobs
crontab -e

# Example: Run a backup script every day at 2 AM
0 2 * * * /home/user/scripts/backup.sh

# Example: Clean temp files every hour
0 * * * * find /tmp -mtime +7 -delete

# Example: Send a weekly report every Friday at 5 PM
0 17 * * 5 /home/user/scripts/weekly-report.sh

Best Practices

  1. Use absolute paths — Cron runs with a minimal environment. Always use full paths for scripts and commands.
  2. Redirect output — By default, cron emails output to the user. Redirect to a log file: 0 2 * * * /path/script.sh >> /var/log/myjob.log 2>&1
  3. Set the PATH — Add PATH=/usr/local/bin:/usr/bin:/bin at the top of your crontab.
  4. Use lock files — Prevent overlapping runs if a job takes longer than the interval.
  5. Test first — Run your command manually before scheduling it. A cron job that fails silently wastes time.
  6. Document your jobs — Add comments above each entry explaining what it does and why.

Build Cron Expressions Visually

No need to memorize syntax. Our visual builder lets you click to create cron expressions with instant descriptions and next run times.

Try Cron Expression Generator

Common Pitfalls

Alternatives to Cron

While cron is the classic tool, modern systems offer alternatives:

Cron remains the most straightforward way to schedule recurring tasks. Use our Cron Expression Generator to build expressions visually and verify them before deploying to production.