BlogResearch

What is a cron job? Meaning, syntax and how it works

A cron job runs a command on a fixed schedule. Learn the five-field syntax, crontab commands, and limits.

Rithul PalazhiRithul PalazhiUpdated 6 min read

Summarize with AI

What is a cron job? Meaning, syntax and how it works
On this page

What is a cron job?

A cron job is a command that a Unix-like system runs automatically on a fixed schedule. The cron daemon, a background program, reads a table of schedules called a crontab and starts each command when its time matches (crontab(5) man page, 2026). Typical uses are nightly backups, log cleanup and polling an API every 15 minutes.

Key Takeaways

  • A cron job is one line in a crontab: five time fields, then the command.
  • The cron daemon checks the crontab every minute and starts matching commands.
  • Cron does not retry failed runs, prevent overlapping runs or remember past runs.
  • For month-end schedules, see cron job last day of month.
  • Cron fits simple jobs on one machine. Multi-step jobs need a workflow tool.

How does a cron job work?

A cron job works through the cron daemon, which wakes up every minute, compares the current time with every schedule in the crontabs, and runs each command that matches (Wikipedia: Cron, 2026). The daemon starts the command and does not wait for the result or record whether it succeeded.

Three parts are involved:

PartWhat it does
Cron daemonBackground process that checks schedules and starts commands
CrontabText file with one schedule and one command per line
CommandAny shell command or script the daemon runs through /bin/sh by default

The name comes from Chronos, the Greek word for time.

What is crontab?

Crontab is the file, and also the command, that holds a user's cron schedules. The crontab command edits that file: crontab -e opens it in an editor, crontab -l lists it and crontab -r removes it (macOS man crontab, tested 30 October 2026; the same three options appear in the Linux manual).

crontab -e   # edit your schedule
crontab -l   # show your schedule
crontab -r   # delete your whole schedule

Every line in the file has the same shape: five time fields, then the command.

How does cron syntax work?

Cron syntax uses five fields separated by spaces: minute, hour, day of month, month and day of week. Each field accepts a number, a range, a list or a step, and the asterisk means every possible value. The POSIX crontab specification defines the format.

┌───────── minute (0-59)
│ ┌─────── hour (0-23)
│ │ ┌───── day of month (1-31)
│ │ │ ┌─── month (1-12)
│ │ │ │ ┌─ day of week (0-7, where 0 and 7 are Sunday)
│ │ │ │ │
* * * * *  command

Cron expression examples

A cron expression is the five time fields without the command. Each expression below was checked on 30 October 2026 with a small field-matching script, using dates that should match and dates that should not. All four gave the expected result.

ExpressionMeaning
0 9 * * 1-59:00 AM, Monday to Friday
*/15 * * * *Every 15 minutes
0 0 1 * *Midnight on the first day of every month
30 14 * * 02:30 PM every Sunday

When both day of month and day of week are restricted, standard cron runs the job when either field matches, not both (Wikipedia: Cron, 2026). That rule is why month-end schedules need a workaround.

Special strings such as @daily and @reboot

Special strings are shortcuts that replace the five time fields. Common cron versions support @hourly, @daily, @weekly, @monthly, @yearly and @reboot, which runs once at startup (Wikipedia: Cron, 2026). @monthly equals 0 0 1 * *, and @daily equals 0 0 * * *. These strings are extensions, so check your system first.

How do you create a cron job?

To create a cron job, run crontab -e, add one line with the schedule and the command, then save and close the editor. The line below runs a backup script at 6:00 AM every day and writes its output to a log file.

PATH=/usr/local/bin:/usr/bin:/bin
0 6 * * * /home/deploy/bin/backup.sh >> /var/log/backup.log 2>&1

Use the full path to the script. In a crontab, a percent sign in the command must be escaped as \%, because cron otherwise treats it as a newline (crontab(5) man page, 2026).

Why does a cron job not run?

A cron job most often fails to run because it executes in a smaller environment than your login shell. Cron sets only a few variables, such as SHELL, HOME and LOGNAME, and does not load your shell profile, so a command that works in a terminal can fail from cron (crontab(5) man page, 2026).

Fixes that work in practice:

  • Set PATH at the top of the crontab, or use full paths to every program.
  • Redirect output with >> file 2>&1 so errors are saved.
  • Set MAILTO to receive the output by email, if the system can send mail.

What are the limits of a cron job?

Cron has four limits: it does not prevent overlapping runs, does not retry failed runs, cannot express every calendar rule and does not store state between runs. These limits come from design. Cron starts commands and leaves everything else to the command.

  • Overlap: if a job takes longer than its interval, cron starts a second copy. Add a lock file inside the script.
  • Failure: a failed run is not retried. The next run happens at the next scheduled time.
  • Calendar rules: "last day of the month" has no standard syntax. See cron job last day of month for tested workarounds.
  • State: cron does not know what the previous run did. The script must track what it has already processed.

What replaced cron?

Nothing has fully replaced cron, because it is still installed on most Unix-like systems. Newer tools cover the cases cron handles poorly, such as missed runs, dependencies between steps and schedules that span several services. Choose a tool by what the job needs, using the table below.

NeedOption
Timer on one Linux machine, with catch-up after downtimesystemd timers, which can run a missed job at the next boot with Persistent=true (systemd.timer manual, 2026)
Managed schedule without a serverCloud schedulers such as AWS EventBridge and Google Cloud Scheduler, which accept cron-style expressions
Steps that depend on each otherWorkflow orchestrators such as Apache Airflow, which model tasks as a DAG (directed acyclic graph)
Schedules across apps and APIsA workflow automation platform

Cloud services differ from standard cron in details. Google Cloud Scheduler uses the standard unix-cron format (Google Cloud docs, 2026), while AWS EventBridge uses six fields.

CodeWords is a workflow automation platform where workflows run on a schedule, on a trigger or on request. You describe the workflow and Cody builds and connects it, so the schedule does not live in a crontab. See workflow automation tools, scheduled task automation, what a workflow engine is and the templates.

FAQs: What Is a Cron Job

What is a cron job vs batch job?

A cron job is a schedule that starts a command at set times. A batch job is a unit of work that processes a group of data without user input. They answer different questions: cron decides when something runs, and a batch job is what runs. Cron often starts batch jobs.

Is cron job legit?

Yes, cron is a standard Unix tool, and POSIX defines the crontab format [POSIX crontab specification]. Cron is legitimate software that administrators use daily. Because cron can run any command, review crontab -l for entries you did not add, and restrict who can edit crontabs on shared servers.

Is cron outdated?

No, cron is still widely used for simple recurring tasks on one machine. It lacks retries, overlap control and state, so newer tools such as systemd timers, cloud schedulers and workflow orchestrators cover those needs [systemd.timer manual, 2026]. Cron remains a reasonable choice for short, self-contained scripts.

Get started today

Your first workflow is free to build.

Describe what you need. Cody handles the build, the connections, and the deployment.