# cron cron is a Unix/Linux job scheduler that runs commands or scripts automatically at specified times or intervals. Configuration is done via crontab (cron table) files. Present on virtually all Unix-like systems. Named after Chronos, the Greek word for time. ## Crontab syntax ``` ┌───────────── minute (0-59) │ ┌───────────── hour (0-23) │ │ ┌───────────── day of month (1-31) │ │ │ ┌───────────── month (1-12) │ │ │ │ ┌───────────── day of week (0-7, 0 and 7 = Sunday) │ │ │ │ │ * * * * * command ``` ## Common examples - `0 * * * *` — every hour - `*/5 * * * *` — every 5 minutes - `0 9 * * 1-5` — weekdays at 9am - `0 0 * * *` — daily at midnight - `@reboot` — once at startup ## Key commands - `crontab -e` — edit current user's crontab - `crontab -l` — list current user's crontab - `crontab -r` — remove current user's crontab ## Common pitfalls - Cron runs with a minimal environment (limited PATH, no shell aliases) - Use absolute paths for commands and scripts - Output goes nowhere by default — redirect to a file or use `MAILTO` - Time zone depends on system configuration ## Alternatives - **systemd timers**: Modern alternative on systemd-based Linux distributions - **anacron**: Runs missed jobs after system wake (useful for laptops) - **at**: One-time scheduled execution ## References - Wikipedia: https://en.wikipedia.org/wiki/Cron - crontab.guru (expression editor): https://crontab.guru ## Related - [[Linux]] - [[Shell]] - [[Automating processes]]