LINUX CRONTAB GUIDE

Linux Crontab
Examples & Reference

30+ real Linux crontab examples with working commands — backups, log rotation, scripts, system maintenance, @reboot jobs, environment variables, and everything you need for crontab -e.

Crontab Syntax Quick Reference

Every crontab line follows this format:

# ┌──────── minute (0–59)
# │ ┌────── hour (0–23)
# │ │ ┌──── day of month (1–31)
# │ │ │ ┌── month (1–12)
# │ │ │ │ ┌ day of week (0–7, 0 and 7 = Sunday)
# │ │ │ │ │
  * * * * *  command-to-run
Common operators:
* — any value  |  */5 — every 5  |  1,3,5 — 1, 3, and 5  |  1-5 — 1 through 5  |  0 — exactly zero (midnight, January, Sunday)

Essential crontab commands

CommandWhat it does
crontab -eEdit your crontab (creates if none exists)
crontab -lList your current crontab
crontab -rRemove your entire crontab (careful!)
crontab -u username -eEdit another user's crontab (requires root)
sudo crontab -eEdit root's crontab
systemctl status cronCheck if the cron daemon is running (Debian/Ubuntu)
systemctl status crondCheck cron daemon (RHEL/CentOS/Fedora)

@shortcut Strings (Special Schedules)

Instead of five time fields, cron supports human-readable shortcuts. These are clearer and less error-prone for common patterns.

ShortcutEquivalent cronMeaning
@reboot(none)Once, at startup / cron daemon start
@yearly or @annually0 0 1 1 *Once a year, Jan 1 at midnight
@monthly0 0 1 * *Once a month, 1st day at midnight
@weekly0 0 * * 0Once a week, Sunday at midnight
@daily or @midnight0 0 * * *Once a day at midnight
@hourly0 * * * *Once an hour, at the top of the hour
# Run a database backup once daily at midnight
@daily /usr/local/bin/db-backup.sh >> /var/log/db-backup.log 2>&1

# Start a custom service at boot
@reboot /usr/local/bin/start-myservice.sh

# Monthly report generation on the 1st
@monthly /usr/local/bin/generate-monthly-report.sh

30+ Linux Crontab Examples

Every N minutes / hours

Every 5 minutes
*/5 * * * *
Useful for health checks, polling tasks, or short-interval monitoring scripts.
Every 15 minutes
*/15 * * * *
Common for syncing data, cache refresh, or fetching external API updates.
Every 30 minutes
*/30 * * * *
Ideal for incremental backups or sending digest notifications.
Every hour on the hour
0 * * * *
Hourly tasks like log archiving or report generation.
Every 2 hours
0 */2 * * *
Runs at 0:00, 2:00, 4:00 … 22:00.
Every 6 hours
0 */6 * * *
Runs at midnight, 6 AM, noon, and 6 PM. Good for periodic data pulls.

Daily jobs

Every day at midnight
0 0 * * *
Classic daily job schedule. Equivalent to @daily or @midnight.
Every day at 2:30 AM
30 2 * * *
Off-peak time for heavier jobs like database dumps or full backups.
Every day at 8:00 AM
0 8 * * *
Morning jobs like sending daily digest emails or generating reports.
Twice a day (midnight and noon)
0 0,12 * * *
Runs at 12:00 AM and 12:00 PM. Use comma for multiple specific hours.

Weekday jobs

Weekdays only at 9 AM
0 9 * * 1-5
Monday through Friday at 9:00 AM. 1=Monday, 5=Friday.
Monday morning report
0 7 * * 1
Every Monday at 7 AM — generate weekly summary before the team starts work.
Weekends only at 4 AM
0 4 * * 6,0
Saturday (6) and Sunday (0) at 4:00 AM for weekend maintenance jobs.
Every Friday at 5 PM
0 17 * * 5
End-of-week cleanup, archive jobs, or weekly report delivery.

Monthly & yearly jobs

1st of every month at midnight
0 0 1 * *
Monthly billing runs, statement generation, or log archiving.
Last day of the month — workaround
0 23 28-31 * *
Runs on 28th–31st, depending on month length. Add a date check in your script for accuracy.
Every quarter (Jan, Apr, Jul, Oct)
0 0 1 1,4,7,10 *
First day of each quarter at midnight. Good for quarterly reporting jobs.
Once a year on Jan 1
0 0 1 1 *
Equivalent to @yearly — annual cleanup, archiving, or reset jobs.

Real-world command examples

Daily MySQL backup
0 2 * * * mysqldump -u root -p'secret' mydb > /backups/mydb-$(date +\%F).sql
Creates a dated SQL dump every day at 2 AM. Note: escape % as \% in crontab.
Clear tmp files weekly
0 3 * * 0 find /tmp -type f -mtime +7 -delete
Deletes files in /tmp older than 7 days every Sunday at 3 AM.
Sync files to S3 every hour
0 * * * * aws s3 sync /data/uploads s3://my-bucket/uploads --delete
Keeps an S3 bucket in sync with a local directory every hour.
Restart service daily
30 4 * * * systemctl restart myapp.service
Restarts a systemd service at 4:30 AM daily as a memory-leak workaround.
Rotate logs and compress
0 0 * * * logrotate /etc/logrotate.conf
Runs logrotate manually at midnight (typically already done by the system, but useful for custom configs).
Ping monitoring check
*/5 * * * * curl -sf https://mysite.com/health || echo "DOWN $(date)" >> /var/log/health.log
Checks a health endpoint every 5 minutes and logs failures.
Run Python script on reboot
@reboot /usr/bin/python3 /home/ubuntu/myapp/run.py >> /var/log/myapp.log 2>&1
Starts a Python process every time the server reboots.
Send disk usage report daily
0 8 * * * df -h | mail -s "Disk Usage Report" admin@example.com
Emails a disk usage summary every morning at 8 AM.

Setting Environment Variables in Crontab

Cron runs with a minimal environment — $PATH is limited and most shell variables are absent. Always set variables at the top of your crontab:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=admin@example.com
HOME=/root
TZ=America/New_York

# Jobs below inherit the above variables
0 9 * * 1-5  /usr/local/bin/weekday-job.sh
Key environment variables for crontab:
SHELL — which shell runs your commands (default: /bin/sh)
PATH — extend this to find your binaries without full paths
MAILTO — email address for cron output; set to "" to silence all email
TZ or CRON_TZ — override timezone for this crontab file
HOME — home directory used by cron jobs
⚠ The % gotcha: Percent signs (%) in crontab commands are interpreted as newlines by cron. Always escape them as \%. This affects date +%F, printf, and any other command using %.

Example: date +\%Y-\%m-\%d not date +%Y-%m-%d

Handling Output & Logging

By default, cron emails all stdout/stderr output to the local user. In most server setups this fills up a mail spool nobody reads. Here are the common patterns:

# Discard all output (no log, no email)
0 2 * * *  /usr/bin/cleanup.sh > /dev/null 2>&1

# Log stdout only, discard stderr
0 2 * * *  /usr/bin/myjob.sh >> /var/log/myjob.log

# Log both stdout and stderr (append)
0 2 * * *  /usr/bin/myjob.sh >> /var/log/myjob.log 2>&1

# Log both with timestamps using bash -c
0 2 * * *  bash -c '/usr/bin/myjob.sh >> /var/log/myjob.log 2>&1; echo "Done at $(date)"'

# Suppress email for all jobs in this crontab
MAILTO=""

# Email output to a specific address per-job
0 2 * * *  MAILTO=ops@example.com /usr/bin/critical-job.sh

System-Wide Crontab: /etc/cron.d/ and /etc/crontab

Beyond per-user crontabs, Linux has system crontab locations. These include an extra username field before the command:

# /etc/crontab or files in /etc/cron.d/
# Format: minute hour dom month dow USER command

0 2 * * *  root  /usr/local/bin/system-backup.sh
*/5 * * * *  www-data  /usr/bin/php /var/www/html/cron.php > /dev/null 2>&1
LocationPurpose
/etc/crontabMain system crontab — requires username field
/etc/cron.d/Directory for package-installed cron jobs — requires username field
/etc/cron.daily/Drop scripts here — run daily by run-parts
/etc/cron.hourly/Scripts run every hour
/etc/cron.weekly/Scripts run weekly
/etc/cron.monthly/Scripts run monthly
/var/spool/cron/crontabs/Per-user crontabs (don't edit directly)

Troubleshooting: Why Isn't My Cron Job Running?

1. Cron daemon not running
Check with systemctl status cron (Debian/Ubuntu) or systemctl status crond (RHEL/CentOS). Start it with systemctl start cron.
2. PATH is too short
Cron's default PATH is usually just /usr/bin:/bin. If your command isn't there, use the full path (e.g. /usr/local/bin/python3) or set PATH at the top of your crontab.
3. Unescaped % signs
The % character is special in crontab. Escape every one as \% — this catches many broken date commands.
4. Script not executable
Run chmod +x /path/to/yourscript.sh. Alternatively call it as bash /path/to/yourscript.sh.
5. Wrong timezone
Cron uses the system timezone. Check with timedatectl. Set TZ in your crontab if you need a specific zone.
6. Syntax error in crontab
Validate with CronRead before saving. A line with bad syntax is silently skipped. Check /var/log/syslog or /var/log/cron for cron error messages.

Frequently Asked Questions

How do I edit my crontab?
Run crontab -e in your terminal. This opens the crontab in your default editor. Each line is one scheduled job. Save and quit to install. To list your current crontab: crontab -l.
What timezone does cron use?
The system timezone by default (check with timedatectl). Override per-file with TZ=America/New_York or CRON_TZ=Europe/London at the top of your crontab.
How do I stop cron from emailing me?
Add MAILTO="" at the top of your crontab to suppress all emails. For individual jobs, redirect output to /dev/null: command > /dev/null 2>&1.
What is the difference between crontab -e and /etc/crontab?
crontab -e edits the per-user crontab (jobs run as that user, no username field needed). /etc/crontab and files in /etc/cron.d/ are system-wide and require a username field in every job line.
Can I run a cron job every second?
No. The minimum granularity in standard cron is one minute. For sub-minute scheduling, use a workaround (run a 1-minute job that sleeps and loops internally) or switch to a different tool like systemd timers or a task queue.
How do I view cron logs?
On Debian/Ubuntu check /var/log/syslog and grep for "cron". On RHEL/CentOS check /var/log/cron. You can also use journalctl -u cron or journalctl -u crond on systemd-based systems.

Related Guides

GuideWhat you'll learn
Cron Expression Examples50+ cron expression patterns with human-readable descriptions
Kubernetes CronJob ExamplesYAML CronJob specs, concurrencyPolicy, history limits
GitHub Actions Cron ExamplesScheduled workflows, UTC gotcha, workflow_dispatch
AWS EventBridge CronAWS 6-field cron syntax, rate() expressions
Cron Syntax GuideDeep-dive into every cron field and operator
⚡ Validate Your Crontab Expression

🔧 Other Free Developer Tools

⏱ Cron Generator 🕐 Timestamp Converter 🔑 JWT Decoder 📄 YAML ↔ JSON 🔤 Base64 Encoder 🗄 SQL Explainer