Cron syntax at a glance
A crontab line is five time fields and then the command. The generator above reads the fields the way the cron on Debian, Ubuntu and the Red Hat family does, and writes the schedule out in plain English with the next times it fires.
┌───────────── 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 are Sunday)
│ │ │ │ │
* * * * * /path/to/command| Character | Meaning | Example |
|---|---|---|
| * | Every value of the field | * * * * * — every minute |
| , | A list of values | 0 8,12,18 * * * — at 08:00, 12:00 and 18:00 |
| - | A range | 0 9 * * 1-5 — 09:00, Monday to Friday |
| / | A step through a range or * | */15 * * * * — every 15 minutes; 5-59/15 starts at minute 5 (5/15 alone is refused by crontab) |
| @daily | A shortcut for a whole schedule | @daily is 0 0 * * *; also @hourly, @weekly, @monthly, @yearly, @reboot |
Cron expression examples
| Expression | Runs |
|---|---|
| */5 * * * * | Every 5 minutes |
| 0 * * * * | Every hour, on the hour |
| 0 */6 * * * | Every 6 hours: 00:00, 06:00, 12:00 and 18:00 |
| 30 3 * * * | Every day at 03:30 |
| 0 9 * * 1-5 | At 09:00 on weekdays |
| 0 4 * * 0 | Sundays at 04:00 |
| 0 0 1 * * | At midnight on the first of every month |
| 0 0 1 1 * | Once a year, on 1 January |
Adding the job on a server
crontab -e opens your own crontab in an editor; crontab -l lists it. Files in /etc/cron.d/ and /etc/crontab take one more field, the user to run as, between the schedule and the command:
# m h dom mon dow user command
30 3 * * * root /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1Cron starts jobs with a short PATH and almost no environment, so use full paths, set what the script needs at the top of the crontab (PATH=…, MAILTO=…), and send the output to a log file — most of the reasons a cron job does not run come down to one of those. For jobs that need dependencies, retries or a log in the journal, a systemd service with a timer is the alternative.
Frequently asked
What do the five fields of a cron expression mean?
In order: minute (0–59), hour (0–23), day of the month (1–31), month (1–12 or JAN–DEC) and day of the week (0–7, where 0 and 7 are both Sunday, or SUN–SAT). An asterisk means every value, a comma separates a list, a hyphen gives a range and a slash a step: */15 in the minute field means every 15 minutes.
Which time zone does cron use?
The time zone of the server the crontab runs on. Most VPS images are set to UTC — check with timedatectl. Some cron implementations, such as cronie on Fedora and the Red Hat family, also honour a CRON_TZ= line in the crontab; the cron that Debian and Ubuntu ship does not. The next run times on this page can be shown for a server on UTC or for one on your own time zone.
What happens when both the day of the month and the day of the week are set?
The job runs when either one matches, not only when both do: 0 9 1 * 1 runs at 09:00 on the first of every month and also on every Monday. That is how Vixie cron and the crons derived from it behave, and the explanation on this page says so whenever an expression restricts both fields.
How do I run a cron job every 5 minutes?
*/5 * * * * — the step in the minute field fires at minutes 0, 5, 10 and so on up to 55, every hour. To start at minute 2 instead, write 2-59/5.
Why does my cron job not run?
Most often the script depends on a PATH or an environment variable that cron does not set, the command contains a % that cron turns into a line break (write \% instead), the crontab file does not end with a newline, or a file in /etc/cron.d has a dot in its name and is skipped. Each run is logged — journalctl -u cron on Debian and Ubuntu.