Blog
Custom Print on Demand Apparel — Free Storefront for Your Business
Wild & Free Tools

Linux Crontab Guide — Setup, Examples & Troubleshooting (2026)

Last updated: April 20268 min readDeveloper Tools

Linux crontab is the built-in job scheduler on every Linux distribution and macOS. Run crontab -e to open your schedule, add a cron expression followed by a command, save, and the system handles the rest. Here is the complete setup, real examples, and fixes for every common problem.

Crontab Commands

CommandWhat It Does
crontab -eEdit your personal crontab (opens in default editor)
crontab -lList all your current cron jobs
crontab -rRemove your entire crontab (use carefully — deletes ALL jobs)
crontab -r -iRemove with confirmation prompt (safer)
sudo crontab -eEdit the root user crontab
sudo crontab -l -u www-dataList cron jobs for a specific user (requires root)

Your First Cron Job

  1. Open your terminal
  2. Run crontab -e — choose nano if prompted for an editor (easiest for beginners)
  3. Add this line at the bottom: */5 * * * * echo "cron works" >> /tmp/crontest.log 2>&1
  4. Save and exit (in nano: Ctrl+O, Enter, Ctrl+X)
  5. Wait 5 minutes, then check: cat /tmp/crontest.log
  6. If you see "cron works" — your crontab is functioning
  7. Remove the test job: run crontab -e and delete the line

Real-World Crontab Examples

Cron ExpressionCommandPurpose
0 2 * * */home/user/scripts/backup.sh >> /var/log/backup.log 2>&1Nightly backup at 2 AM
*/5 * * * */usr/bin/python3 /home/user/healthcheck.pyHealth check every 5 min
0 9 * * 1-5/home/user/scripts/report.sh | mail -s "Daily Report" [email protected]Weekday 9 AM report
0 0 * * 0/usr/sbin/logrotate /etc/logrotate.confWeekly log rotation
0 */6 * * */usr/bin/certbot renew --quietSSL cert renewal check every 6 hrs
30 4 1 * */home/user/scripts/monthly-cleanup.sh > /dev/null 2>&1Monthly cleanup, no output

Crontab vs System Cron Directories

Linux has two ways to schedule cron jobs: user crontabs and system cron directories. Both are active simultaneously.

LocationManaged ByUse CaseIncludes Username Field
crontab -eIndividual usersUser-specific scheduled tasksNo (runs as that user)
/etc/crontabSystem adminSystem-wide jobs with user specificationYes (root, www-data, etc.)
/etc/cron.d/Package managers, adminIndividual cron files per serviceYes
/etc/cron.hourly/System (run-parts)Scripts that run every hourN/A (just executable scripts)
/etc/cron.daily/System (run-parts)Scripts that run daily (~6:25 AM)N/A
/etc/cron.weekly/System (run-parts)Scripts that run weekly (Sunday ~6:47 AM)N/A
/etc/cron.monthly/System (run-parts)Scripts that run monthly (1st ~6:52 AM)N/A

The /etc/cron.daily/ and similar directories are the simplest option for interval-based jobs — just drop an executable script into the directory. No cron expression needed. The system scheduler (anacron) handles the timing.

The #1 Problem: PATH Issues

Cron runs with a minimal environment — typically PATH=/usr/bin:/bin. This means commands that work in your terminal may fail in cron because cron cannot find them.

Fix: always use full paths in cron jobs.

Alternatively, set PATH at the top of your crontab:

Troubleshooting Cron Jobs

ProblemDiagnosisFix
Job not running at allCheck if cron service is active: systemctl status cronsudo systemctl start cron && sudo systemctl enable cron
Command not found errorsPATH issue — cron has minimal PATHUse full paths: /usr/bin/python3 instead of python3
Permission deniedScript not executablechmod +x /path/to/script.sh
No output or error messagesOutput goes to mail or nowhereAdd >> /tmp/job.log 2>&1 to capture output
Job runs but produces wrong resultsEnvironment variables missingSource your env in the script: source /home/user/.env
Job runs at wrong timeTimezone mismatchCheck with timedatectl — cron uses system timezone
Job seems to run multiple timesOverlapping executionsAdd flock lock: flock -n /tmp/job.lock /path/to/script.sh
Cron email flooding inboxEvery job output goes to user mailAdd > /dev/null 2>&1 or set MAILTO="" in crontab

Checking Cron Logs

Cron logs show when each job started but NOT the output. To capture job output, redirect it in the cron line itself: 0 9 * * * /path/to/job.sh >> /var/log/myjob.log 2>&1

Build cron expressions visually instead of hand-writing them. Verify before deploying.

Open Cron Generator

macOS Crontab vs launchd

macOS supports crontab identically to Linux. However, Apple officially recommends launchd as the preferred scheduler:

Featurecrontablaunchd (plist)
Setup complexity✓ Simple — one-line cron expression~Complex — XML plist files
Time-based scheduling✓ Yes — standard cron syntax✓ Yes — StartCalendarInterval
Run after sleep/wake✗ Missed jobs are skipped✓ Catches up missed jobs
Event-based triggers✗ Time only✓ File changes, network events, login
Logging~Manual redirect✓ Built-in stdout/stderr paths
Process management✗ No restart on failure✓ KeepAlive, restart policies
Best for✓ Simple scheduled scripts~Complex daemons and agents

For simple scheduled tasks (backups, scripts, health checks), crontab on macOS is perfectly fine. Use launchd when you need event-driven triggers or want the system to catch up on missed jobs after sleep.

When Cron Is Not Enough

Cron is excellent for simple, time-based scheduling on a single machine. You will outgrow it when you need:

Developer Tools

Generate valid cron expressions in seconds — no syntax errors, no guessing.

Open Cron Generator
Launch Your Own Clothing Brand — No Inventory, No Risk