crontab Command in Linux: Schedule Jobs, Syntax & Examples

crontab installs and edits per-user cron tables — the schedule files the cron daemon reads to run commands at fixed times. Use it to list, edit, validate, and remove recurring jobs without touching spool files by hand.

Published

Updated

Read time 9 min read

Reviewed byDeepak Prasad

crontab Command in Linux: Schedule Jobs, Syntax & Examples
About crontab installs and edits per-user cron tables — the schedule files the cron daemon reads to run commands at fixed times. Use it to list, edit, validate, and remove recurring jobs without touching spool files by hand.
Tested on Ubuntu 25.04 (Plucky Puffin); cron 3.0pl1-194ubuntu1; kernel 7.0.0-27-generic
Package cron
Man page crontab(1)
Privilege user / sudo for other users
Distros

Debian, Ubuntu, RHEL, and most Linux distros with Vixie/BSD cron (cron package).

One-shot delays: at command. System-wide files: /etc/cron.d/, /etc/cron.daily/, etc.

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):

text
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:

bash
crontab -l

Sample output when empty:

text
no crontab for root

That 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:

bash
printf '*/5 * * * * /bin/true\n' > /tmp/install.cron
crontab /tmp/install.cron
crontab -l

Sample output:

text
*/5 * * * * /bin/true

crontab 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:

bash
printf '* * * * * /bin/true\n' > /tmp/test.cron
crontab -n /tmp/test.cron

Sample output:

text
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:

bash
crontab -r
crontab -l

Sample output:

text
no crontab for root

Use -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:

bash
printf '@daily /usr/local/bin/backup.sh\n' > /tmp/daily.cron
crontab -n /tmp/daily.cron

Sample output:

text
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.

bash
systemctl is-active cron
systemctl status cron --no-pager | head -8

Sample output:

text
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:

bash
printf '* * * * * /path/script.sh >> /tmp/cron.log 2>&1\n' > /tmp/log.cron
crontab -n /tmp/log.cron

Sample output:

text
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:

bash
sudo crontab -u www-data -l

Sample output when empty:

text
no crontab for www-data

Install 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:

bash
printf '60 * * * * /bin/true\n' > /tmp/bad.cron
crontab -n /tmp/bad.cron 2>&1

Sample output:

text
"/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
  • You need a recurring command on a calendar or interval (minute, hour, daily, weekly)
  • The job should run as a specific user with that user's environment and permissions
  • You are editing a user schedule file — list, install, or remove with crontab
  • You want @daily, @hourly, or five-field cron expressions
  • One-shot "run at 3 PM once" → at
  • Package-maintainer scripts on a schedule → /etc/cron.daily/ and friends (managed by the package, not your user crontab)
  • System-wide drop-in jobs with their own user field → /etc/cron.d/
  • Modern timer units with richer dependencies → systemd timers
  • Sub-minute scheduling or complex orchestration → workflow tools, not classic cron

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.


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.

bash
crontab -l

User 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.

text
* * * * * 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:

bash
crontab -l > /tmp/cron.bak 2>/dev/null
echo '0 2 * * * /path/job' >> /tmp/cron.bak
crontab /tmp/cron.bak

A 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.


Rohan Timalsina

is a technical writer and Linux enthusiast who writes practical guides on Linux commands and system administration. He focuses on simplifying complex topics through clear explanations.