How to Run a Cron Job Every 5 Minutes (Linux, Mac, Docker)
Cron is the standard Unix task scheduler, and knowing how to write cron expressions correctly is a fundamental skill for any developer or sysadmin. This guide covers the exact expression for every 5 minutes, explains the full crontab syntax, and provides a reference for every common schedule you will encounter.
The Answer: Cron Expression for Every 5 Minutes
If you just need the expression:
*/5 * * * * /path/to/your/command
Breaking this down:
*/5- every 5 minutes (the*/nsyntax means "every n units")*- every hour*- every day of the month*- every month*- every day of the week
This job will run at: 00:00, 00:05, 00:10, 00:15, 00:20, 00:25, 00:30, 00:35, 00:40, 00:45, 00:50, 00:55, 01:00, 01:05... and so on, 288 times per day.
Understanding the Crontab Syntax
A crontab line has 5 time/date fields followed by the command to run:
# ┌───────────── minute (0–59)
# │ ┌───────────── hour (0–23)
# │ │ ┌───────────── day of month (1–31)
# │ │ │ ┌───────────── month (1–12)
# │ │ │ │ ┌───────────── day of week (0–6, Sun=0 or 7)
# │ │ │ │ │
# * * * * * command to execute
Special Characters
*- wildcard, matches every value in the field*/n- step: every n-th value (e.g.,*/5in minutes = 0, 5, 10, 15...)n-m- range: every value from n to m (e.g.,9-17in hours = 9am to 5pm)n,m,p- list: specific values (e.g.,1,15,28in day = 1st, 15th, 28th)n-m/s- range with step (e.g.,0-30/5in minutes = 0, 5, 10, 15, 20, 25, 30)
Complete Reference: Common Cron Schedules
Minute Intervals
# Every minute
* * * * * command
# Every 2 minutes
*/2 * * * * command
# Every 5 minutes
*/5 * * * * command
# Every 10 minutes
*/10 * * * * command
# Every 15 minutes
*/15 * * * * command
# Every 20 minutes
*/20 * * * * command
# Every 30 minutes
*/30 * * * * command
Hourly and Daily
# Every hour (at the top of the hour)
0 * * * * command
# Every hour at :30
30 * * * * command
# Every 2 hours
0 */2 * * * command
# Every 6 hours
0 */6 * * * command
# Every day at midnight
0 0 * * * command
# Every day at 6am
0 6 * * * command
# Every day at 11:30pm
30 23 * * * command
# Twice a day (midnight and noon)
0 0,12 * * * command
Weekly
# Every Monday at 9am
0 9 * * 1 command
# Every weekday (Mon-Fri) at 9am
0 9 * * 1-5 command
# Every weekend at 10am
0 10 * * 6,0 command
# Every Sunday at midnight
0 0 * * 0 command
Monthly
# First day of every month at midnight
0 0 1 * * command
# Last day of the month is tricky - no direct syntax
# Use a workaround:
0 0 28-31 * * [ "$(date +\%d -d tomorrow)" = "01" ] && command
# Every quarter (Jan, Apr, Jul, Oct) on the 1st
0 0 1 1,4,7,10 * command
# First Monday of every month
0 9 1-7 * 1 command
@reboot and Special Strings
Many cron implementations support shorthand strings:
@reboot command # run once at startup
@hourly command # same as: 0 * * * *
@daily command # same as: 0 0 * * *
@midnight command # same as: 0 0 * * *
@weekly command # same as: 0 0 * * 0
@monthly command # same as: 0 0 1 * *
@yearly command # same as: 0 0 1 1 *
@annually command # same as: 0 0 1 1 *
Generate Cron Expressions Visually
Build and validate your crontab schedule with our free visual crontab generator. See exactly when your job will run next.
Open Crontab GeneratorStep-by-Step: Adding a Cron Job
- Open your crontab file in an editor:
crontab -e - Write your expression followed by the full path to your command
- Save and exit - cron picks up changes automatically, no reload needed
- Verify it was saved:
crontab -l - Monitor the first run: check
/var/log/syslogor/var/log/cron
# Open crontab for current user
crontab -e
# Open crontab for a specific user (as root)
crontab -u www-data -e
# List current user's crontab
crontab -l
# Delete current user's crontab (careful!)
crontab -r
Real-World Cron Job Examples
Database Backup Every Night at 2am
0 2 * * * /usr/bin/mysqldump -u root -p'password' mydb > /backups/mydb-$(date +\%Y\%m\%d).sql 2>&1
Clear Temporary Files Every Sunday at 3am
0 3 * * 0 find /tmp -type f -mtime +7 -delete 2>&1 | logger -t cleanup
Restart a Service if It is Down (Every 5 Minutes)
*/5 * * * * systemctl is-active --quiet myservice || systemctl start myservice
Run a PHP Script Every 5 Minutes (Magento Cron)
*/5 * * * * /usr/bin/php /var/www/html/bin/magento cron:run >> /var/www/html/var/log/magento.cron.log 2>&1
Sync Files to S3 Hourly
0 * * * * /usr/local/bin/aws s3 sync /var/www/uploads s3://my-bucket/uploads --delete >> /var/log/s3-sync.log 2>&1
Send a Daily Report at 8am Weekdays
0 8 * * 1-5 /opt/scripts/send-daily-report.sh
SSL Certificate Renewal Check Twice Daily
0 0,12 * * * /usr/bin/certbot renew --quiet
Best Practices for Cron Jobs
- Use absolute paths: Cron runs with a minimal environment. Never rely on
PATH- always use/usr/bin/python3, not justpython3. - Redirect output: By default, cron emails output to the cron owner. Redirect to a log file:
command >> /var/log/myjob.log 2>&1 - Suppress output entirely: If you do not want any output:
command > /dev/null 2>&1 - Test your command first: Run the exact command manually before scheduling it. Cron's environment differs from your shell.
- Use flock to prevent overlapping runs: If a job might run longer than its interval, use
flockto prevent parallel execution. - Log with timestamps: Use
dateat the start of your script for easier debugging. - Set MAILTO to empty to disable emails: Add
MAILTO=""at the top of your crontab.
# Example crontab with best practices
MAILTO=""
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Every 5 minutes - prevent overlap with flock
*/5 * * * * flock -n /tmp/myjob.lock /opt/scripts/myjob.sh >> /var/log/myjob.log 2>&1
Troubleshooting Cron Jobs
When a cron job does not run as expected, work through this checklist:
- Check cron is running:
systemctl status cron(Debian) orsystemctl status crond(RHEL/CentOS) - Check syslog for cron entries:
grep CRON /var/log/syslog | tail -20 - Verify the crontab was saved:
crontab -l - Run the command manually as the cron user:
sudo -u www-data /path/to/command - Check for PATH issues: Add
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binat the top of your crontab - Check file permissions: The script must be executable (
chmod +x script.sh) and readable by the cron user - Check for newline at end of crontab: Some implementations require a trailing newline after the last cron entry
# View recent cron activity in syslog
grep CRON /var/log/syslog | tail -50
# View cron log on RHEL/CentOS
cat /var/log/cron | tail -50
# Check if crond is running
pgrep -x cron || pgrep -x crond
Cron in Modern Environments
While crontab is the classic tool, modern environments have additional options:
- systemd timers: A more powerful alternative on systems using systemd. Supports logging, dependencies, and more complex scheduling.
- Kubernetes CronJobs: Schedule containerized jobs in Kubernetes using the same cron expression syntax.
- GitHub Actions scheduled workflows: Also use standard cron syntax for
scheduletriggers. - AWS EventBridge (CloudWatch Events): Uses a modified cron syntax with a 6th field for year.
- Celery Beat: Python task scheduler for applications that need cron-like scheduling with result tracking.
FAQ
Why is my cron job not running even though the expression looks correct?
The most common causes are: (1) the command uses a relative path that is not in cron's minimal PATH, (2) the script is not executable, (3) the crontab has no trailing newline, or (4) cron itself is not running. Start by checking /var/log/syslog for CRON entries to see if cron is even attempting to run the job.
What is the difference between */5 and 0/5 in cron?
In standard crontab syntax, */5 and 0/5 are equivalent - both mean "every 5 minutes starting at 0". The start/step syntax (like 0/5) is common in Quartz cron expressions (Java/Spring) but not standard POSIX cron. Stick with */5 for maximum compatibility.
How do I run a cron job every 2 minutes?
Use */2 * * * * command. This runs at :00, :02, :04, :06, and so on. The minimum interval in standard cron is 1 minute. For sub-minute scheduling, you need a different tool like a while loop in a background process or a systemd timer with OnCalendar=*:*:0/30.
Does cron use UTC or local time?
Cron uses the system's local timezone by default. You can set a specific timezone per crontab by adding CRON_TZ=UTC (or any valid TZ name) at the top of the crontab file. This is important for servers in different timezones or when DST transitions could cause jobs to skip or run twice.
How do I view the logs for a specific cron job?
The cleanest approach is to redirect all output from your script to a log file: command >> /var/log/myjob.log 2>&1. Then use tail -f /var/log/myjob.log to monitor it in real time. Alternatively, check /var/log/syslog for the cron daemon's entries which show each time it launches your job.
Can I run a cron job at a specific time on a specific day?
Yes. Combine day-of-month, month, and day-of-week fields. For example, to run at 9am on December 25th: 0 9 25 12 * command. To run at 9am every Monday in January: 0 9 * 1 1 command. Note: when both day-of-month and day-of-week are specified (not wildcards), cron runs the job when either condition is true, not when both are true.
Use our free tool here → Crontab Generator & Expression Builder
Usman has 10+ years of experience securing enterprise infrastructure, managing high-traffic servers, and building zero-knowledge security tools. Read more about the author.