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.
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
* — any value |
*/5 — every 5 |
1,3,5 — 1, 3, and 5 |
1-5 — 1 through 5 |
0 — exactly zero (midnight, January, Sunday)
| Command | What it does |
|---|---|
crontab -e | Edit your crontab (creates if none exists) |
crontab -l | List your current crontab |
crontab -r | Remove your entire crontab (careful!) |
crontab -u username -e | Edit another user's crontab (requires root) |
sudo crontab -e | Edit root's crontab |
systemctl status cron | Check if the cron daemon is running (Debian/Ubuntu) |
systemctl status crond | Check cron daemon (RHEL/CentOS/Fedora) |
Instead of five time fields, cron supports human-readable shortcuts. These are clearer and less error-prone for common patterns.
| Shortcut | Equivalent cron | Meaning |
|---|---|---|
@reboot | (none) | Once, at startup / cron daemon start |
@yearly or @annually | 0 0 1 1 * | Once a year, Jan 1 at midnight |
@monthly | 0 0 1 * * | Once a month, 1st day at midnight |
@weekly | 0 0 * * 0 | Once a week, Sunday at midnight |
@daily or @midnight | 0 0 * * * | Once a day at midnight |
@hourly | 0 * * * * | 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
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
SHELL — which shell runs your commands (default: /bin/sh)PATH — extend this to find your binaries without full pathsMAILTO — email address for cron output; set to "" to silence all emailTZ or CRON_TZ — override timezone for this crontab fileHOME — home directory used by cron jobs
%) in crontab commands are interpreted as newlines by cron. Always escape them as \%. This affects date +%F, printf, and any other command using %.
date +\%Y-\%m-\%d not date +%Y-%m-%d
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
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
| Location | Purpose |
|---|---|
/etc/crontab | Main 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) |
systemctl status cron (Debian/Ubuntu) or systemctl status crond (RHEL/CentOS). Start it with systemctl start cron.
/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.
% character is special in crontab. Escape every one as \% — this catches many broken date commands.
chmod +x /path/to/yourscript.sh. Alternatively call it as bash /path/to/yourscript.sh.
timedatectl. Set TZ in your crontab if you need a specific zone.
/var/log/syslog or /var/log/cron for cron error messages.
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.timedatectl). Override per-file with TZ=America/New_York or CRON_TZ=Europe/London at the top of your crontab.MAILTO="" at the top of your crontab to suppress all emails. For individual jobs, redirect output to /dev/null: command > /dev/null 2>&1.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.systemd timers or a task queue./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.| Guide | What you'll learn |
|---|---|
| Cron Expression Examples | 50+ cron expression patterns with human-readable descriptions |
| Kubernetes CronJob Examples | YAML CronJob specs, concurrencyPolicy, history limits |
| GitHub Actions Cron Examples | Scheduled workflows, UTC gotcha, workflow_dispatch |
| AWS EventBridge Cron | AWS 6-field cron syntax, rate() expressions |
| Cron Syntax Guide | Deep-dive into every cron field and operator |