It is 9:14 on a Monday and you are staring at a log file that should be full. The nightly backup was supposed to run at 2 a.m. The report was supposed to land in the shared folder before the team woke up. Neither happened. Nobody got an error, nobody got a page — the job simply did not run, and the silence is the worst part. If you have ever had this morning, you already know the quiet terror of a scheduled task that never fired.

The tool at the center of that story is almost always cron, the scheduler that has been running Linux and Unix systems since the 1970s. It is ancient, it is everywhere, and it is wonderfully reliable right up until the moment you make one of its small, classic mistakes. This guide walks through cron the way you would actually learn it on the job: the syntax field by field, examples you can copy, the traps that eat your Monday morning, and the moment when its modern cousin, the systemd timer, is the better tool.

What cron actually is

Cron is a background service — a daemon — that wakes up once a minute, checks a list of scheduled jobs, and runs whichever ones are due. That list lives in files called crontabs (short for "cron tables"). Each line in a crontab is one job: a schedule on the left, a command on the right. When the clock matches the schedule, cron runs the command. That is the entire idea.

The reason cron feels confusing at first is that it is really two systems wearing the same name. There is your personal crontab, which you edit with crontab -e and which runs commands as you. And there are system crontabs, living in files like /etc/crontab and directories like /etc/cron.d/, which run as whichever user the line specifies and are usually managed by administrators or installed by software packages. For day-to-day automation — a backup, a cleanup, a sync — your personal crontab is where you want to be.

The golden rule: crontab -e edits your jobs, crontab -l lists them, and crontab -r deletes all of them. That last one has no confirmation prompt, so treat it like a loaded tool.

The five fields, decoded

Every classic cron schedule is five fields separated by spaces, followed by the command. Read left to right, they are minute, hour, day-of-month, month, and day-of-week.

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

The magic is in the symbols you put in each field. An asterisk (*) means "every value." A number means that exact value. And three combiners cover almost everything else: a comma lists specific values (1,15 = the 1st and the 15th), a hyphen gives a range (9-17 = 9 a.m. through 5 p.m.), and a slash gives a step (*/15 = every 15 units).

Here is the same concept turned into real jobs you would plausibly write:

# Every day at 2:00 AM — the classic nightly backup
0 2 * * * /home/alex/scripts/backup.sh

# Every 15 minutes, around the clock
*/15 * * * * /home/alex/scripts/sync.sh

# Weekdays at 9:00 AM only (Monday=1 through Friday=5)
0 9 * * 1-5 /home/alex/scripts/morning-report.sh

# The 1st of every month at midnight
0 0 1 * * /home/alex/scripts/invoice-run.sh

A concrete way to read the third line: minute 0, hour 9, any day of the month, any month, days-of-week 1-5. So it fires at 9:00 a.m. Monday through Friday and stays quiet on the weekend. Once the five fields click, you can read any crontab in the world — including the mysterious ones you inherit from the person who had your job before you.

Shortcuts that save keystrokes

Most cron implementations accept a handful of named shortcuts that stand in for the whole five-field schedule. They read more clearly than a row of numbers, and they are harder to get wrong.

ShortcutEquivalentMeaning
@hourly0 * * * *Top of every hour
@daily0 0 * * *Midnight every day
@weekly0 0 * * 0Midnight every Sunday
@monthly0 0 1 * *Midnight on the 1st
@reboot—Once, when the system boots

The one worth special attention is @reboot, which runs a job a single time each time the machine starts up. It is perfect for launching a long-running helper or re-creating a temporary directory, and it is a tidy alternative to more elaborate startup scripts for simple needs.

The four mistakes that eat your morning

Almost every "my cron job didn't run" story traces back to the same short list. Learn these four and you will skip most of the pain.

The PATH is nearly empty. When you run a command in your terminal, your shell knows where to find python3, node, pg_dump, and everything else, because your login profile builds a rich PATH for you. Cron does not load that profile. It runs with a minimal environment, so a script that works perfectly when you type it can fail under cron with "command not found." The fix is simple and non-negotiable: use absolute paths. Write /usr/bin/python3 instead of python3, and point at your script with its full path, not a relative one.

# Fragile — depends on an environment cron doesn't have
0 2 * * * python3 backup.py

# Robust — nothing is left to chance
0 2 * * * /usr/bin/python3 /home/alex/scripts/backup.py

The percent sign is secretly special. Inside a crontab, an unescaped % character is turned into a newline, which quietly breaks commands that use it — date formats are the usual victim. If your command contains %, escape each one as \% or wrap the logic inside a script file where normal shell rules apply. This one is genuinely baffling the first time it bites you, because the command looks flawless.

You never see the output. By default cron captures whatever your job prints and tries to email it to you, which on most modern servers means it vanishes into a mail system nobody reads. The cure is to send output somewhere you will actually look. Redirect both normal output and errors to a log file, and suddenly your jobs can tell you what happened.

# Append standard output and errors to a dated log
0 2 * * * /home/alex/scripts/backup.sh >> /home/alex/logs/backup.log 2>&1

That 2>&1 is the piece people forget: it means "send error output to the same place as normal output." Without it, the most important messages — the ones explaining the failure — are exactly the ones you lose.

The timezone is not what you think. Cron runs against the system's clock and timezone, not yours. On a cloud server that often means UTC, so your "2 a.m. job" may be firing at 11 a.m. local time. Before you trust a schedule, check the box's timezone with timedatectl and do the math, or set the timezone explicitly for your jobs where your cron version supports a CRON_TZ line at the top of the crontab.

Testing without waiting until 2 a.m.

The slowest way to debug a cron job is to fix it, then wait a day to see if your fix worked. You do not have to. The trick is to separate two questions: does the command work? and does the schedule fire?

For the first, run your exact command line by hand, ideally with a deliberately stripped-down environment so it resembles cron's world: env -i /bin/bash -c '/usr/bin/python3 /home/alex/scripts/backup.py'. If it fails there, it will fail under cron, and you have found your bug without waiting. For the second, temporarily set the schedule to * * * * * so the job runs every minute, watch your log file fill in, and then restore the real schedule once you have seen it fire. A minute of impatience beats a day of guessing.

When a systemd timer is the better choice

On modern Linux distributions, cron now has a capable sibling: the systemd timer. Instead of one terse line, a timer is described by two small files — a service that says what to run and a timer that says when — and it plugs into the same system that already manages your other services. That extra structure buys you real advantages.

The standout feature is Persistent=true. A classic cron job that was scheduled for 2 a.m. while the laptop was asleep simply never happens; the moment passes and cron shrugs. A persistent systemd timer notices the missed run on the next boot and executes it, which is exactly what you want for a laptop or any machine that is not on around the clock. Timers also give you proper logging through journalctl, built-in randomized delays to stop a hundred servers from stampeding a service at the same instant, and clean dependency handling so a job can wait until the network is actually up.

# /etc/systemd/system/backup.timer
[Unit]
Description=Nightly backup

[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true

[Install]
WantedBy=timers.target

So which should you reach for? For a quick personal job on a server that runs continuously, cron is faster to write and perfectly adequate — there is no shame in a one-line crontab. Reach for a systemd timer when you need missed jobs to catch up, when you want searchable logs and real failure handling, or when the task is part of a larger service you already manage with systemd. They are not rivals so much as a simple tool and a sturdier one; knowing both means you always have the right size of wrench.

The takeaway

Cron is one of those rare tools that you can learn in an afternoon and use for the rest of your career. The five fields are just minute, hour, day, month, and weekday. The symbols — star, comma, hyphen, slash — cover every schedule you will realistically need. And the failures are not mysterious once you know them: use absolute paths, redirect your output with 2>&1, escape your percent signs, and check the server's timezone before you trust it. When you need catch-up runs and better logging, a systemd timer is waiting one step up.

So the next time 9:14 on a Monday rolls around, open crontab -l, read your jobs with the confidence of someone who actually understands them, and go get the coffee you earned. The job ran. You made sure of it.