To run a cron job every 5 minutes, use the expression */5 * * * *. This schedules the command to execute at minute intervals of 0, 5, 10, and so on, throughout the entire day. The asterisks in the remaining fields ensure the job runs regardless of the hour, day, month, or weekday.
Understanding the Basic Syntax
The standard cron expression consists of five fields separated by spaces: minute, hour, day of month, month, and day of week. Each field defines when the job should run. For an interval-based schedule like every 5 minutes, the asterisk (*) in the hour, day, month, and weekday fields means "every value," ensuring the job runs continuously throughout the day without skipping specific hours or days.
The minute field */5 means every minute divisible by 5, not every 12 minutes. The expression */5 * * * * runs the job at minute 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, and 55 of every hour.
Step-by-Step Configuration Guide
Start by identifying the script or command you want to execute. For this example, assume you have a backup script located at /usr/local/bin/backup.sh. Open your terminal and edit your crontab file using the command crontab -e. This opens your personal cron schedule in a text editor. Add the following line to the bottom of the file:
*/5 * * * * /usr/local/bin/backup.sh
Save and exit the editor. The system automatically reloads the configuration. If you prefer not to edit the file manually, you can append the line directly using a one-liner command:
echo "*/5 * * * * /usr/local/bin/backup.sh" | crontab -
This command pipes the expression directly into the crontab utility. Note that this replaces existing entries if you do not use the -l flag to list current jobs first, so manual editing is often safer for preserving other jobs. Once saved, the job is active immediately. The next execution will occur at the next multiple of 5 minutes relative to the current time. For instance, if it is 10:03, the job runs at 10:05. If it is 10:06, it waits until 10:10.
Verifying Next Fire Times
Calculating the exact next execution time manually can be error-prone, especially when accounting for timezone differences or daylight saving time changes. Instead of guessing, verify the schedule by observing the output or using a tool that parses the expression. When you input */5 * * * * into a cron explainer, it confirms the logic: "Runs every 5 minutes." It then lists the upcoming execution timestamps. For example, if the current time is Tuesday at 14:03, the next ten firing times would be:
- Tuesday 14:05
- Tuesday 14:10
- Tuesday 14:15
- Tuesday 14:20
- Tuesday 14:25
- Tuesday 14:30
- Tuesday 14:35
- Tuesday 14:40
- Tuesday 14:45
- Tuesday 14:50
This preview ensures that your job does not skip hours or days unexpectedly. If you are using a system that supports the 6-field format (including seconds), adding a leading asterisk for seconds (* */5 * * * *) would run the job every second within the 5-minute intervals, which is rarely desired for standard backups. Stick to the 5-field format for minute-level precision. You can use CronExplain to paste your expression and instantly see this list of next-fire times in your local timezone, confirming that the schedule aligns with your operational needs before deploying to production.
Common Pitfalls and Fixes
One frequent mistake is confusing */5 with 0,5,10,15.... While both achieve similar results, */5 is cleaner and automatically handles the full hour cycle. However, be cautious with field placement. The expression */5 * * * * correctly runs every 5 minutes. If you mistakenly write * */5 * * *, the scheduler interprets the first asterisk as "every minute" and the second as "every 5 hours," resulting in a job that runs every minute during hours divisible by 5 (hours 0, 5, 10, 15, 20). This is incorrect for minute-level intervals. Always place the interval modifier in the first field.
Another common issue is missing output redirection. By default, cron captures stdout and stderr. If your script produces verbose logs, this can fill up your mail spool. Redirect output explicitly:
*/5 * * * * /usr/local/bin/backup.sh > /var/log/backup.log 2>&1
This ensures logs are written to a file rather than sent via email. Finally, ensure your script has execute permissions. Cron runs with a minimal environment, so absolute paths for both the script and any dependencies are crucial. Relative paths often fail silently.
Using Visual Builders for Accuracy
Memorizing cron syntax is difficult, and errors in field order can cause unexpected behavior. A visual builder simplifies this process by allowing you to select values from dropdown menus rather than typing raw strings. For an every-5-minutes schedule, you would select "Every" from the minute dropdown and choose "5" from the interval options. The builder then generates */5 * * * * automatically. This method eliminates typos and ensures the remaining fields default to the correct "every" values. It also provides immediate feedback on what the expression means in plain English. When you build complex schedules involving specific weekdays or months, the visual interface prevents logic errors by constraining choices to valid combinations. This approach is particularly useful for teams where multiple people manage schedules, as it standardizes the format and reduces debugging time.