Recuro.

Crontab

Quick Summary — TL;DR

  • Crontab (cron table) is the file where you define scheduled commands — each line pairs a cron expression with a shell command.
  • Use crontab -e to edit, crontab -l to list, and crontab -r to remove your crontab entries.
  • Per-user crontabs run as the owning user; the system crontab (/etc/crontab) has an extra user field and is managed by root.

A crontab (short for cron table) is the configuration file that tells the cron daemon which commands to run and when to run them. Each line in a crontab pairs a cron expression with a shell command. The cron daemon reads these files every minute and executes any commands whose schedule matches the current time.

Crontab vs the cron daemon

The cron daemon is the background process that does the actual scheduling and execution. The crontab is the file it reads to know what to run. Think of the cron daemon as the engine and the crontab as the instruction sheet. You never interact with the daemon directly — you edit the crontab, and the daemon picks up the changes automatically.

Managing your crontab

The crontab command is also the CLI tool used to manage your cron schedule file. Three flags cover most use cases:

Command Description
crontab -eOpen your crontab in the default editor. Changes take effect immediately on save.
crontab -lPrint your current crontab entries to stdout.
crontab -rDelete your entire crontab. There is no confirmation prompt — be careful.

On multi-user systems, administrators can manage another user's crontab with crontab -u username -e.

Crontab file format

Each line in a crontab follows the same structure: five time fields followed by the command to execute.

Field Allowed values
Minute0 – 59
Hour0 – 23
Day of month1 – 31
Month1 – 12
Day of week0 – 6 (Sunday = 0)

For example, 30 2 * * 1 /usr/local/bin/backup.sh runs backup.sh every Monday at 2:30 AM. For a detailed breakdown of the syntax, including wildcards, ranges, and step values, see the cron expression reference. You can also build expressions interactively with our cron expression generator.

Environment variables in crontab

Crontab entries run in a minimal shell environment — not the interactive shell you're used to. This catches people off guard. You can set environment variables at the top of the crontab file, and they apply to all entries below them:

If a command works in your terminal but fails silently in cron, the most likely culprit is a missing PATH entry. Always use absolute paths for commands or set PATH at the top of your crontab.

Per-user vs system crontab

Per-user crontabs are stored in /var/spool/cron/ (Linux) or /var/at/tabs/ (macOS). Each user manages their own file via crontab -e. Commands run as the owning user.

The system crontab at /etc/crontab has an extra field between the time fields and the command: the username to run the command as. Files in /etc/cron.d/ follow the same format. These are managed by root and are typically used for system maintenance tasks like log rotation and package updates.

Feature Per-user crontab System crontab
Location/var/spool/cron//etc/crontab, /etc/cron.d/
Managed bycrontab -eDirect file editing (root)
User fieldNo (runs as owner)Yes (specify which user)
Typical useApplication-level tasksOS maintenance

Common crontab gotchas

FAQ

What is the difference between cron and crontab?

Cron (the cron daemon) is the background process that executes scheduled commands. Crontab is the file that contains those scheduled commands — the schedule itself. You edit the crontab; the cron daemon reads it and runs the commands.

Where is the crontab file located?

Per-user crontabs are stored in /var/spool/cron/crontabs/ on most Linux distributions and /var/at/tabs/ on macOS. You shouldn't edit these files directly — use crontab -e instead, which validates the syntax before saving. The system crontab is at /etc/crontab.

How do I edit my crontab?

Run crontab -e in your terminal. This opens the crontab in your default editor (set via the EDITOR or VISUAL environment variable). Add one entry per line in the format: cron expression followed by the command. Save and exit — changes take effect immediately.

The crontab defines schedules using cron expressions and is read by the cron daemon every minute. For recurring work that needs retries, alerting, and execution history — features crontab lacks — teams move to a dedicated job scheduler. Check out common cron expression examples for patterns you can paste directly into your crontab.

Stop managing infrastructure. Start scheduling jobs.

Recuro handles cron scheduling, retries, alerts, and execution logs -- so you can focus on building your product.

No credit card required