Crontab examples for Linux
Use this cheat sheet when you know when a job should run and need the five fields to put in crontab -e. Pick a schedule below, then add the command you want cron to run.
Common cron schedules
Read the fields from left to right: minute, hour, day of month, month, and day of week. Linux cron uses a 24-hour clock. Sunday is 0 or 7 in Debian cron.
| When it runs | Cron expression |
|---|---|
| Every minute | * * * * * |
| Every 5 minutes | */5 * * * * |
| Every 15 minutes | */15 * * * * |
| Every 30 minutes | 0,30 * * * * |
| At the start of every hour | 0 * * * * |
| Every 2 hours, starting at midnight | 0 */2 * * * |
| Every day at midnight | 0 0 * * * |
| Every day at 6:30 AM | 30 6 * * * |
| Weekdays at 9:00 AM | 0 9 * * 1-5 |
| Weekends at 9:00 AM | 0 9 * * 0,6 |
| Every 15 minutes on weekdays, 9:00 AM–4:45 PM | */15 9-16 * * 1-5 |
| Every Monday at 8:30 AM | 30 8 * * 1 |
| On the first of each month at 2:00 AM | 0 2 1 * * |
| On the first of each quarter at 7:00 AM | 0 7 1 1,4,7,10 * |
Use the crontab visualizer to preview a schedule. Compare its times with the clock on the server that will run the job.
Add the command after the schedule
Say you already have a report script at /home/alex/bin/report.sh and want it to run before work. Open the crontab as the account that should own the report, then add a line like this one.
30 6 * * 1-5 /bin/bash /home/alex/bin/report.sh >> "$HOME/report.log" 2>&1
Replace the example path, and run the command by hand as that user before scheduling it. The example appends both normal output and errors to a file in the user's home directory. In /etc/crontab or /etc/cron.d/, add the account name between the fifth field and the command.
Three schedules that look right at first
Every 5 minutes vs. five minutes past the hour
*/5 * * * * matches minutes 0, 5, 10, and so on. 5 * * * * matches only minute 5. If a job runs once an hour when you expected twelve runs, check that first field.
Every 90 minutes
Steps reset within their own field. To get 00:00, 01:30, 03:00, 04:30, and so on by the server's clock, use two entries for the same command.
0 0-23/3 * * * /bin/bash /home/alex/bin/report.sh
30 1-23/3 * * * /bin/bash /home/alex/bin/report.sh
Those are wall-clock times. If you need a fixed elapsed interval across clock changes, use an interval-based timer.
The first Monday of the month
On Debian cron, 0 9 1-7 * 1 runs at 9:00 AM on every Monday and on each of the first seven days of the month. Cron treats the two restricted day fields as alternatives. Schedule every Monday, then check the date in the script.
# In crontab
0 9 * * 1 /bin/sh /home/alex/bin/first-monday.sh
# At the top of first-monday.sh
[ "$(date +%d)" -le 7 ] || exit 0
The % in this example belongs in the script. If you put it directly into a crontab command, escape it as \%.
Check the first run
Run crontab -l after saving to confirm the entry is installed for the right account. Then check the output after the first scheduled run. If nothing appears, follow the cron troubleshooting guide to tell whether cron started the job or the command failed.
See the Debian crontab manual for field ranges, step values, and how cron combines the two day fields.