crontab — quick reference
Manage your crontab
Per-user schedule file — always edit through crontab, not by hand in /var/spool/cron/crontabs.
| When to use | Command |
|---|---|
Edit the current user's jobs (opens $EDITOR) |
crontab -e |
| List the current user's jobs | crontab -l |
| Replace jobs from a text file | crontab filename |
Check syntax without installing (-n dry run) |
crontab -n filename |
| Remove all jobs for the current user | crontab -r |
| Remove with confirmation prompt | crontab -i -r |
| Show built-in usage | crontab -h |
Other users (root)
Administrators manage another account's table with -u.
| When to use | Command |
|---|---|
| List another user's jobs | sudo crontab -u username -l |
| Edit another user's jobs | sudo crontab -u username -e |
| Remove another user's jobs | sudo crontab -u username -r |
| Remove with confirmation for another user | sudo crontab -u username -i -r |
Cron daemon
| When to use | Command |
|---|---|
| Check whether cron is running (Ubuntu/Debian service name) | systemctl status cron |
| See if cron is active | systemctl is-active cron |
Schedule patterns (in crontab file lines)
Five time fields then the command: MIN HOUR DOM MON DOW COMMAND.
| When to use | Line |
|---|---|
| Every minute | * * * * * command |
| Every hour at minute 0 | 0 * * * * command |
| Daily at midnight | 0 0 * * * command |
| Weekly (Sunday 00:00) | 0 0 * * 0 command |
| Monthly on the 1st at midnight | 0 0 1 * * command |
| Weekdays at 09:00 | 0 9 * * 1-5 command |
| Every 15 minutes | */15 * * * * command |
Special time strings
Readable shortcuts defined by cron — equivalent five-field forms exist.
| When to use | Line |
|---|---|
| Once per year (midnight Jan 1) | @yearly command |
| Once per month (midnight, 1st) | @monthly command |
| Once per week (midnight Sunday) | @weekly command |
| Once per day (midnight) | @daily command |
| Once per hour (minute 0) | @hourly command |
| At cron daemon startup | @reboot command |
crontab — command syntax
Usage from crontab -h on Ubuntu 25.04 (cron 3.0pl1):
crontab [-u user] [-n] file
crontab [ -u user ] [ -i ] { -e | -l | -r }-n checks syntax only (dry run). User crontabs live under /var/spool/cron/crontabs/ on Debian/Ubuntu — install and edit them only through crontab. Access may be restricted by /etc/cron.allow and /etc/cron.deny.
crontab — command examples
Essential List crontab — none configured yet
Before adding jobs, see whether the current user already has a table.
Run the command:
crontab -lSample output when empty:
no crontab for rootThat message is normal on a fresh account — not an error. After you install jobs, the same command prints each schedule line.
Essential Install jobs from a file and verify
Keep schedules in git as a plain file, validate syntax, then load with crontab file.
Create a job file and install it:
printf '*/5 * * * * /bin/true\n' > /tmp/install.cron
crontab /tmp/install.cron
crontab -lSample output:
*/5 * * * * /bin/truecrontab filename replaces the entire table for that user — include every line you want to keep, not only the new job.
Essential Dry-run syntax check with -n
Catch typos in time fields before they replace a production crontab.
Run the command:
printf '* * * * * /bin/true\n' > /tmp/test.cron
crontab -n /tmp/test.cronSample output:
The syntax of the crontab file was successfully checked.On failure, cron prints which line broke — fix the file and run -n again before installing.
Essential Remove all jobs and confirm empty
-r deletes the user's entire crontab — use after tests or when decommissioning an account.
Remove and list:
crontab -r
crontab -lSample output:
no crontab for rootUse -i -r in interactive sessions to get a yes/no prompt before deletion.
Common @daily shortcut in a job file
Special strings are easier to read than five asterisk fields.
Example file content:
printf '@daily /usr/local/bin/backup.sh\n' > /tmp/daily.cron
crontab -n /tmp/daily.cronSample output:
The syntax of the crontab file was successfully checked.@daily is equivalent to 0 0 * * * — midnight every day. Prefer absolute paths in the command field; cron's PATH is minimal.
Common Confirm the cron daemon is running
Jobs do not run if the scheduler is stopped — check service state after reboots or package upgrades.
Run the command:
Confirm the unit state with systemctl status or is-active; the systemctl command shows exit codes and recent journal lines in one view.
systemctl is-active cron
systemctl status cron --no-pager | head -8Sample output:
active
● cron.service - Regular background program processing daemon
Loaded: loaded (/usr/lib/systemd/system/cron.service; enabled; preset: enabled)
Active: active (running) since Wed 2026-07-01 15:30:41 IST; 5min ago
Docs: man:cron(8)
Main PID: 1071 (cron)On RHEL-family systems the unit may be named crond instead of cron. Editing a crontab usually does not require restarting the service — see when to restart cron.
Common Capture stdout and stderr from a job
Cron emails output to the owning user by default on some setups — redirecting to a log file makes debugging easier.
Example line to validate:
printf '* * * * * /path/script.sh >> /tmp/cron.log 2>&1\n' > /tmp/log.cron
crontab -n /tmp/log.cronSample output:
The syntax of the crontab file was successfully checked.>> appends each run; 2>&1 merges errors into the same file. Rotate or truncate the log so it cannot fill the disk.
Common List another user's crontab (root)
Admins use -u to inspect service accounts without switching login.
Run the command:
sudo crontab -u www-data -lSample output when empty:
no crontab for www-dataInstall or edit with sudo crontab -u www-data -e — the file still lives in the spool, owned by that user.
Advanced Syntax error — invalid minute field
Too many time columns is a frequent mistake when copying examples.
Run the command:
printf '60 * * * * /bin/true\n' > /tmp/bad.cron
crontab -n /tmp/bad.cron 2>&1Sample output:
"/tmp/bad.cron":0: bad minute
errors in crontab file, can't install.There are only five time fields before the command (minute 0–59). The error names the bad field — fix the line and run crontab -n again before installing.
crontab — when to use / when not
| Use crontab when | Use something else when |
|---|---|
|
|
crontab vs /etc/cron.d
User crontab (crontab -e) |
/etc/cron.d/ snippets |
|
|---|---|---|
| Who edits | Each user (root for others with -u) |
root / packages |
| Format | Five time fields + command | Same, but line includes user column |
| Typical use | Personal automation, app owners | System and package jobs |
User crontabs never include a username column — the file owner is the run-as user.
Related commands
| Command | One line |
|---|---|
| crontab | Per-user schedule install/list/edit (this page) |
| create cron job shell script | End-to-end scripting walkthrough |
at |
One-time scheduled commands |
Browse the full index in our Linux commands reference.
crontab — interview corner
What is crontab in Linux?
crontab is the command that installs, lists, and edits a user's cron table. The cron daemon reads those tables and executes commands when the time fields match.
crontab -lUser tables on Debian/Ubuntu live in /var/spool/cron/crontabs/ — edit them only through crontab, not with a text editor directly.
A strong answer is:
"crontab manages per-user cron tables; cron runs the jobs. I use crontab -e/-l and never edit the spool file by hand."
What are the five cron time fields?
Order is minute, hour, day-of-month, month, day-of-week, then the command.
* * * * * command
│ │ │ │ │
│ │ │ │ └── day of week (0–7, 0 and 7 = Sunday)
│ │ │ └──── month (1–12)
│ │ └────── day of month (1–31)
│ └──────── hour (0–23)
└────────── minute (0–59)A strong answer is:
"Minute, hour, day of month, month, day of week — then the command. Asterisk means every value in that field."
Why might a cron job not run?
Common causes: wrong path to the script (cron's PATH is tiny), missing execute permission, environment variables not set in the crontab, cron daemon stopped, or syntax errors in the line. The user must be allowed in cron.allow / not denied in cron.deny.
A strong answer is:
"I check absolute paths, permissions, env vars in the crontab, cron service status, and syslog — then crontab -n for syntax."
Does crontab filename add or replace jobs?
It replaces the entire crontab for that user. To add one line, merge with existing content:
crontab -l > /tmp/cron.bak 2>/dev/null
echo '0 2 * * * /path/job' >> /tmp/cron.bak
crontab /tmp/cron.bakA strong answer is:
"crontab file replaces the whole table — I dump with -l, append, and reinstall, or use crontab -e."
What does @daily mean in crontab?
@daily is a shortcut for 0 0 * * * — run once per day at midnight. Similar macros: @hourly, @weekly, @monthly, @yearly, @reboot.
A strong answer is:
"@daily is midnight every day — same as 0 0 * * *. @reboot runs once when cron starts after boot."
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Job never runs | Relative path or missing PATH |
Use absolute paths; set PATH= at top of crontab |
errors in crontab file, can't install |
Syntax error in time fields | Run crontab -n file; fix line cited in the error |
You (user) are not allowed to use crontab |
cron.deny / cron.allow policy |
Adjust allow/deny lists or use root |
| No output visible | Mail disabled; stdout not redirected | Add >> /var/log/myjob.log 2>&1 |
| Edits ignored | Edited spool file directly | Use crontab -e only |
| Wrong timezone | Cron uses system timezone | Set TZ= in crontab or fix system timezone |
| Service down | cron not running |
sudo systemctl start cron and enable on boot |
Cron evaluates schedules in the system timezone. On Ubuntu, set timezone on Ubuntu walks through GUI and timedatectl set-timezone before you add per-job TZ= overrides.
