What Is a Cron Job? Beginner's Guide to Task Scheduling

Utilko Team 5 min read Developer

What Is a Cron Job?

A cron job is a scheduled task that runs automatically at specified times or intervals on Unix-like systems (Linux, macOS). The name comes from Chronos, the Greek god of time. Cron is the daemon (background process) that executes these jobs; the schedule definitions live in a file called the crontab (cron table).

Cron jobs are used for an enormous range of automation tasks: sending daily email reports, clearing expired sessions from a database, backing up files, fetching data from APIs, generating sitemaps, and more. If something needs to happen on a schedule, cron is usually how to do it.

Understanding Cron Syntax

Each cron job is defined by a single line with six fields:

┌───────────── minute (0–59)
│ ┌─────────── hour (0–23)
│ │ ┌───────── day of month (1–31)
│ │ │ ┌─────── month (1–12 or JAN–DEC)
│ │ │ │ ┌───── day of week (0–7, 0 and 7 are Sunday, or SUN–SAT)
│ │ │ │ │
* * * * * command_to_run

An asterisk (*) means "every" — every minute, every hour, etc.

Cron Expression Examples

Expression Meaning
* * * * *Every minute
0 * * * *At the start of every hour
0 0 * * *Daily at midnight
0 8 * * 1Every Monday at 8:00 AM
0 0 1 * *1st of every month at midnight
*/15 * * * *Every 15 minutes
0 9-17 * * 1-5Every hour from 9 AM to 5 PM, Monday–Friday
0 0 * * 0,6Midnight on Saturday and Sunday

Special Syntax

  • */n — Every n units (e.g., */5 in the minute field = every 5 minutes)
  • n-m — A range (e.g., 9-17 in hours = 9 AM through 5 PM)
  • n,m — A list (e.g., 1,15 in days = the 1st and 15th)

Build Cron Expressions Visually

Use our free Cron Expression Generator to build and test cron schedules with a human-readable preview — no memorizing syntax required.

Cron Expression Generator →

How to Edit Your Crontab

On Linux and macOS, open your user crontab with:

crontab -e

This opens the file in your default editor (usually nano or vi). Add one job per line, save, and exit. To list current jobs:

crontab -l

To remove all cron jobs for the current user:

crontab -r

System-Wide vs. User Crontabs

Each user on a Unix system has their own crontab. Additionally, the system crontab at /etc/crontab and directories like /etc/cron.daily/, /etc/cron.weekly/ allow root to run system-wide jobs. These have an extra field for the username:

0 2 * * * root /usr/bin/backup.sh

Cron in Cloud & Modern Environments

Traditional cron is Linux-only, but the concept has been adopted everywhere:

  • GitHub Actions — Use on: schedule: cron: "0 0 * * *" to trigger workflows on a schedule.
  • AWS EventBridge — Supports cron and rate expressions for Lambda functions.
  • Kubernetes CronJobs — Run containerized tasks on a cron schedule.
  • Vercel / Netlify — Scheduled functions using cron syntax.
  • Heroku Scheduler — A simplified scheduler for Heroku apps.

Best Practices

  • Log everything — Redirect cron output to a log file: command >> /var/log/myjob.log 2>&1
  • Test your command manually before adding it to crontab to verify it works as expected.
  • Use absolute paths — Cron has a minimal environment; relative paths and shell aliases will not work.
  • Consider time zones — Cron runs in the server's local time zone. Document this clearly and consider using UTC.
  • Avoid overlapping jobs — If a job takes longer than its interval, use a lock mechanism to prevent parallel runs.

Conclusion

Cron jobs are one of the most useful tools in any developer's toolkit. Whether you are running database cleanups, sending scheduled emails, or syncing external data, a well-crafted cron expression gets the job done reliably. Use our Cron Expression Generator to build your schedules without memorising the syntax.

Tools Mentioned in This Article