What Is a Cron Job? Cron Expression Syntax Explained

By FreeToolBox Team · ·
croncron jobschedulerlinuxdeveloperautomation

If you have ever needed a script to run automatically at midnight, a backup to fire every Sunday, or a report to generate on the first of each month, you have needed a cron job. Cron is one of the oldest and most widely used scheduling tools in computing — and once you understand its syntax, it becomes indispensable.


What Is a Cron Job?

A cron job is a scheduled task managed by the cron daemon, a background process that runs on Unix-like operating systems (Linux, macOS, BSD). The word “cron” comes from the Greek chronos, meaning time.

The daemon wakes up every minute, checks a configuration file called the crontab (cron table), and executes any commands whose schedule matches the current time. That is the entire mechanism — deceptively simple, remarkably powerful.

Cron jobs are used for:

  • Running database backups at low-traffic hours
  • Sending scheduled emails or notifications
  • Clearing temporary files and logs
  • Fetching data from external APIs on a fixed schedule
  • Generating reports or invoices automatically

The Crontab File

Each user on a Unix system can have their own crontab. You edit it with:

crontab -e

Each line in the file represents one scheduled job and follows this structure:

* * * * *  command-to-run
│ │ │ │ │
│ │ │ │ └─ Day of week (0–7, where 0 and 7 = Sunday)
│ │ │ └─── Month (1–12)
│ │ └───── Day of month (1–31)
│ └─────── Hour (0–23)
└───────── Minute (0–59)

Five fields, separated by spaces or tabs, followed by the command to execute. That is the entire format.


Understanding Each Field

Minute (0–59)

The minute field controls which minute of the hour the job fires.

  • 0 — at the top of the hour (e.g. 14:00, 15:00)
  • 30 — at half past the hour (e.g. 14:30)
  • */15 — every 15 minutes
  • 5,20,45 — at minutes 5, 20, and 45

Hour (0–23)

Cron uses a 24-hour clock.

  • 0 — midnight
  • 9 — 9 AM
  • */2 — every two hours
  • 8-17 — every hour from 8 AM to 5 PM

Day of Month (1–31)

  • 1 — the first of the month
  • 15 — the 15th
  • */7 — roughly every week (days 1, 8, 15, 22, 29)
  • 1,15 — the 1st and the 15th

Month (1–12)

  • 1 — January
  • 6 — June
  • */3 — every quarter (January, April, July, October)
  • 1-6 — January through June

Day of Week (0–7)

Both 0 and 7 represent Sunday. Monday is 1, Saturday is 6.

  • 1 — every Monday
  • 1-5 — weekdays
  • 6,0 — weekends
  • */2 — every other day of the week

Special Characters

Beyond simple numbers, cron supports several special characters that make expressions more expressive.

CharacterMeaningExample
*Every value* * * * * — every minute
,List of values1,15 — 1st and 15th
-Range9-17 — 9 AM to 5 PM
/Step*/5 — every 5 units

Common Cron Expressions

Here are the patterns you will use most often:

# Every minute
* * * * *

# Every hour, on the hour
0 * * * *

# Every day at midnight
0 0 * * *

# Every day at 9 AM
0 9 * * *

# Every Monday at 8 AM
0 8 * * 1

# Every weekday at 6 PM
0 18 * * 1-5

# Every Sunday at 2 AM
0 2 * * 0

# First day of every month at midnight
0 0 1 * *

# Every 15 minutes
*/15 * * * *

# Every 6 hours
0 */6 * * *

# Twice a day (midnight and noon)
0 0,12 * * *

Special Strings (Shortcuts)

Many cron implementations accept convenient named shortcuts instead of the five-field syntax:

ShortcutEquivalentMeaning
@yearly0 0 1 1 *Once a year, 1 Jan at midnight
@monthly0 0 1 * *Once a month, 1st at midnight
@weekly0 0 * * 0Once a week, Sunday at midnight
@daily0 0 * * *Once a day at midnight
@hourly0 * * * *Once an hour, on the hour
@rebootOnce, at system startup

These shortcuts are supported on Linux (Vixie cron, cronie) and macOS, but not all minimal cron implementations include them. When in doubt, use the explicit five-field form.


A Practical Example

Suppose you want to run a Python backup script every day at 3:30 AM and log the output:

30 3 * * * /usr/bin/python3 /home/alice/backup.py >> /var/log/backup.log 2>&1

Breaking this down:

  • 30 3 * * * — 3:30 AM, every day
  • /usr/bin/python3 /home/alice/backup.py — the command (use full paths in crontab)
  • >> /var/log/backup.log — append stdout to a log file
  • 2>&1 — redirect stderr to the same log file

Always use absolute paths in cron commands. The cron environment is minimal — $PATH may not include the directories you expect.


Testing and Debugging Cron Jobs

Cron is notoriously silent when things go wrong. A few tips:

  • Always redirect output to a log file so you can inspect errors.
  • Test your command manually in a terminal before scheduling it.
  • Use full paths for both the interpreter and the script.
  • Check system logs — on Linux, look at /var/log/syslog or journalctl -u cron.
  • Mind the environment — cron does not load your .bashrc or .profile. Set any required environment variables explicitly inside the crontab.

Build and Validate Cron Expressions Online

Writing cron expressions by hand is error-prone. One misplaced field and your job runs at the wrong time — or not at all.

Our free Cron Expression Generator lets you:

  • Build expressions visually using dropdown fields for each position
  • See a plain-English explanation of any expression in real time
  • Choose from 14 common presets (hourly, daily, weekly, and more)
  • Copy the final expression with one click — no sign-up, no tracking

If you manage scheduled tasks regularly, bookmark it — it takes the guesswork out of the syntax entirely.


Alternatives to Classic Cron

Cron is the standard on Unix servers, but several modern alternatives exist:

  • Systemd timers — the Linux systemd init system has a built-in scheduling mechanism that integrates with service management and journald logging.
  • Cloud schedulers — AWS EventBridge, Google Cloud Scheduler, and Azure Logic Apps offer managed cron-like scheduling without needing a server.
  • Application-level schedulers — libraries like Celery Beat (Python), node-cron (Node.js), and Quartz (Java) run within your application process.
  • Monitoring-aware tools — services like Cronitor wrap your cron jobs with uptime monitoring, alerting you when a job fails or does not run on time.

For small-to-medium projects on a Linux server, classic cron remains the simplest and most reliable option. For distributed systems or cloud-native architectures, a managed scheduler often makes more sense.


Summary

Cron jobs are one of the most useful tools in any developer’s or sysadmin’s toolkit. The syntax looks cryptic at first, but follows a consistent five-field pattern:

minute  hour  day-of-month  month  day-of-week  command

Once that pattern clicks, you can schedule almost anything — from a nightly backup to a quarterly report — with a single line of configuration.

Use the Cron Expression Generator to build and validate your expressions visually, then paste them straight into your crontab.