Video: Linux/Mac Tutorial: Cron Jobs — How to Schedule Commands with crontab (Corey Schafer). Embedded from YouTube in privacy-enhanced mode; all rights belong to the creator.
Cron has scheduled recurring work on Unix systems since the 1970s, and its syntax lives on in Kubernetes CronJobs, GitHub Actions schedules, cloud schedulers and countless job queues. Learn it once and you'll use it everywhere.
Crontab syntax
┌───────── minute (0–59)
│ ┌─────── hour (0–23)
│ │ ┌───── day of month (1–31)
│ │ │ ┌─── month (1–12 or JAN–DEC)
│ │ │ │ ┌─ day of week (0–7 or SUN–SAT; 0 and 7 = Sunday)
│ │ │ │ │
* * * * * command-to-run
Edit your user's schedule with crontab -e and list it with crontab -l.
Patterns you'll reuse
| Expression | Runs |
|---|---|
*/5 * * * * | Every 5 minutes |
0 * * * * | Every hour, on the hour |
30 2 * * * | Daily at 02:30 |
0 9 * * 1-5 | Weekdays at 09:00 |
0 0 1 * * | Midnight on the 1st of each month |
@reboot | Once at startup |
Paste any expression into the cron explainer to see it in plain English with the next run times.
The pitfalls that bite everyone
- Minimal environment. Cron runs with a tiny
PATHand none of your shell profile. Use absolute paths (/usr/bin/python3) or setPATHat the top of the crontab. - Silent failures. Output is mailed locally or discarded. Redirect it:
... >> /var/log/backup.log 2>&1. - Percent signs. In crontab,
%means newline — escape it as\%(common withdate +%F). - Overlapping runs. If a job takes longer than its interval, copies pile up. Wrap it with
flock -n /tmp/job.lock. - Day-of-month OR day-of-week. When both are restricted, cron fires if either matches — not both.
- Time zones and DST. Jobs at 02:00–03:00 local time may skip or double-run on daylight-saving changes. Schedule critical jobs in UTC.
Monitoring
A cron job that silently stops is worse than one that fails loudly. Have each job ping a heartbeat monitor on success; if the ping doesn't arrive on schedule, you get an alert.
Beyond cron
On modern Linux, systemd timers add logging, dependencies and catch-up for missed runs. In the cloud, Kubernetes CronJobs, AWS EventBridge Scheduler and GitHub Actions schedule: all accept cron syntax — though cloud schedulers usually evaluate it in UTC.
Try the tools
Cron Expression Explainer
Translate cron schedules to plain English and preview next runs.
Unix Timestamp Converter
Convert epoch seconds/milliseconds to dates and back.