What is Cron?

Cron is a time-based job scheduler in Unix-like operating systems that enables users to schedule commands or scripts to run automatically at specified intervals. It uses a special syntax called cron expression to define when tasks should execute.

Quick Facts

Full NameCron Job Scheduler
Created1979 by Ken Thompson
SpecificationOfficial Specification

How Cron Works

Cron was originally written by Ken Thompson for Version 7 Unix in 1979. The name comes from the Greek word 'chronos' meaning time. A cron expression consists of five or six fields representing minute, hour, day of month, month, day of week, and optionally year. Each field can contain specific values, ranges, lists, or special characters like asterisk (*) for 'any value'. Cron is fundamental to system administration for tasks like log rotation, backups, and scheduled maintenance.

Key Characteristics

  • Uses five or six field expression syntax (minute, hour, day, month, weekday)
  • Supports special characters: * (any), , (list), - (range), / (step)
  • Runs in the background as a daemon process
  • Each user can have their own crontab file
  • Expressions are evaluated in the system's local timezone
  • Supports @yearly, @monthly, @weekly, @daily, @hourly shortcuts

Common Use Cases

  1. Scheduling automated backups
  2. Running periodic system maintenance tasks
  3. Sending scheduled reports and notifications
  4. Log rotation and cleanup
  5. Triggering CI/CD pipelines at specific times

Example

# Cron Expression Format:
# ┌───────────── minute (0-59)
# │ ┌───────────── hour (0-23)
# │ │ ┌───────────── day of month (1-31)
# │ │ │ ┌───────────── month (1-12)
# │ │ │ │ ┌───────────── day of week (0-6, Sunday=0)
# │ │ │ │ │
# * * * * *

0 9 * * *       # Every day at 9:00 AM
*/15 * * * *    # Every 15 minutes
0 0 1 * *       # First day of every month at midnight
0 8-17 * * 1-5  # Every hour from 8 AM to 5 PM, Monday to Friday

Related Tools on QubitTool

Related Concepts