Cron is a time-based job scheduler in Unix-like operating systems that runs commands or scripts automatically at specified intervals using a compact expression syntax. Named after Chronos (Greek for time), cron has been a core Unix utility since the 1970s.
Cron expression syntax
A standard cron expression has five fields:
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-7, where 0 and 7 are Sunday)
│ │ │ │ │
* * * * * command
Special characters expand the syntax:
*— every value,— list separator (1,15= 1st and 15th)-— range (1-5= Monday through Friday)/— step values (*/15= every 15 units)
Common examples
0 * * * * Every hour, on the hour
*/5 * * * * Every 5 minutes
0 9 * * 1-5 9:00 AM, Monday through Friday
0 0 1 * * Midnight on the 1st of every month
30 2 * * 0 2:30 AM every Sunday
0 */6 * * * Every 6 hours
Managing crontab
Each user has a crontab (cron table) file. Manage it with:
crontab -e # Edit your crontab
crontab -l # List your crontab
crontab -r # Remove your crontab
System-wide cron jobs live in /etc/crontab and /etc/cron.d/, plus the directories /etc/cron.daily/, /etc/cron.hourly/, etc.
Practical tips
- Redirect output: Cron emails output to the user by default. Redirect to a log file:
0 * * * * /path/to/script.sh >> /var/log/myjob.log 2>&1 - Use absolute paths: Cron runs with a minimal
$PATH. Always use full paths for commands and scripts. - Environment variables: Cron doesn’t load your shell profile. Set variables at the top of your crontab or source them explicitly.
- Timezone: Cron uses the system timezone. In Docker containers or cloud servers, verify this matches your expectations.
Cron in modern infrastructure
While classic cron runs on a single machine, the pattern has expanded:
- Kubernetes CronJobs: Schedule containerized workloads
- GitHub Actions: Cron syntax triggers scheduled workflows
- AWS EventBridge / CloudWatch Events: Serverless scheduled tasks
- systemd timers: A modern alternative to cron on Linux with better logging and dependency handling
Parse and validate expressions with the Cron Expression Parser, translate to readable English with Crontab to English, or reference syntax with the Cron Cheatsheet.