What is a cron job: cron syntax, expressions and examples
What cron and a cron job are, how to read a cron expression, ready-made examples, how to add a job with crontab, why a cron job isn't running and how to replace WP-Cron in WordPress.

A nightly backup, clearing out old logs, sending a report every morning, checking that the website is up every five minutes. These are all tasks nobody wants to run by hand. On a Linux server there's an old and remarkably reliable tool for exactly this: cron.
In this article you'll learn what cron is and what a cron job is, how to read a cron expression, how to add your own job, and which examples are the most useful. You'll also see why cron jobs sometimes "don't run", how to troubleshoot them, and how to use cron to replace WP-Cron in WordPress.
In short
- Cron is a Linux program that runs commands automatically on a schedule. Each of these commands is called a cron job.
- The schedule is written as a cron expression with five fields: minute, hour, day of the month, month and day of the week. For example,
0 3 * * *means every day at 03:00. - You add jobs with
crontab -eand list them withcrontab -l. - The most common reasons a job doesn't run are relative paths, a different environment (PATH) and the wrong time zone.
- Redirect a job's output to a log file so you can see what happened.
What is cron
Cron is a system service (daemon) in Linux and other Unix systems that runs commands and scripts automatically at a set time or interval. The name comes from the Greek word for time, chronos. Cron first appeared in Unix back in the 1970s, and today it runs on practically every Linux server.
The service runs constantly in the background. Every minute it checks the list of jobs and starts the ones whose time has come. You don't need to be logged in to the server: once a job is set up, it runs on its own until you remove it.

On AlmaLinux and Rocky Linux the service is called crond, and on Ubuntu and Debian it's cron. You can check whether it's running with systemctl status crond or systemctl status cron.
What is a cron job and a crontab
A cron job is a single line that tells cron when to run something and what to run. The line has two parts: a schedule, written as a cron expression, and the command to run.
Jobs are stored in a file called a crontab (short for cron table). Every user on the server has their own crontab, and the jobs in it run with that user's permissions. Besides personal crontabs there are system ones too: /etc/crontab, the /etc/cron.d/ folder, and the /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly folders, where scripts run once a day, week or month respectively.
How to read a cron expression
A cron expression is a string of five fields, separated by spaces, that describes when a job should run. From left to right, the fields are minute, hour, day of the month, month and day of the week. The command comes after them.
| Field | Allowed values | Example |
|---|---|---|
| Minute | 0–59 | 30 = at minute 30 |
| Hour | 0–23 | 3 = at 3 a.m. |
| Day of the month | 1–31 | 1 = on the 1st |
| Month | 1–12 or jan–dec | 6 = in June |
| Day of the week | 0–7 or sun–sat (0 and 7 are Sunday) | 1 = on Monday |
Besides numbers, the fields also accept a few special characters for describing repeating schedules:
*means "every value". An asterisk in the hour field means every hour.,lists values.1,15in the day field means on the 1st and the 15th.-sets a range.1-5in the day-of-week field means Monday to Friday./sets a step.*/10in the minute field means every 10 minutes.
One rule often trips up even experienced administrators. If you set both the day of the month and the day of the week, cron runs the job when either one matches, not both. The expression 0 9 13 * 5 will run on every 13th of the month and every Friday, not just on Friday the 13th.

Cron expression examples
Here are the most commonly used schedules. You can copy them and just change the command.
| Cron expression | When it runs |
|---|---|
* * * * * |
Every minute |
*/5 * * * * |
Every 5 minutes |
0 * * * * |
At the start of every hour |
0 3 * * * |
Every day at 03:00 |
30 8 * * 1-5 |
On weekdays at 08:30 |
0 2 * * 0 |
Every Sunday at 02:00 |
0 0 1 * * |
At midnight on the 1st of every month |
15 4 1,15 * * |
On the 1st and 15th at 04:15 |
0 */6 * * * |
Every 6 hours (00:00, 06:00, 12:00, 18:00) |
0 9-18 * * 1-5 |
Every hour from 9 a.m. to 6 p.m. on weekdays |
There are also shorthand strings that replace the whole schedule: @hourly (every hour), @daily (every day at midnight), @weekly, @monthly, @yearly and @reboot. The last one is especially useful: it runs the command once every time the server starts.
How to add a cron job
Jobs are managed with the crontab command. If you're new to the command line, take a look at our article on Linux commands first, because you'll need the basics here.
- Open your crontab for editing. Run
crontab -e. The first time, the system may ask which editor to use. If you're not sure, choose nano. - Add a line for the job. On a new line, type the schedule and the command, for example
0 3 * * * /root/scripts/backup.sh. - Save and exit. In nano that's Ctrl+O, Enter and Ctrl+X. If the syntax is correct, you'll see a message saying the new crontab has been installed.
- Check it.
crontab -lshows all your jobs.
You don't need to restart cron after a change. The service picks up the new crontab on its own. If you're logged in as root and want to edit another user's jobs, use crontab -u ivan -e.
Be careful with crontab -r. This command deletes all your jobs at once without asking, and the letter r sits right next to e on the keyboard. Before any major change, save a copy: crontab -l > crontab-backup.txt.
How to write commands that work under cron
The most common frustration is a command that works perfectly when you run it by hand but does nothing under cron. The reason is almost always that cron runs jobs in a far more limited environment than your terminal session.
- Use full paths. Cron has a minimal PATH, usually just
/usr/bin:/bin. Write/usr/bin/phpinstead ofphpand/var/www/site/script.phpinstead ofscript.php. You can find the full path to a program withwhich php. - Don't rely on the current folder. The job doesn't start from the folder you were in. If the script uses relative paths, start the command with
cd /var/www/site &&. - Escape the % sign. In a crontab, the
%character means a new line. If a command contains a date such asdate +%F, you need to writedate +\%F. - Redirect the output. Add
>> /var/log/backup.log 2>&1to the end of the command. That way both normal output and errors go to a log file you can read later. - Make the script executable. If you're running your own script, it needs execute permission:
chmod +x /root/scripts/backup.sh.
A complete line that follows all these rules looks like this: 0 3 * * * cd /var/www/site && /usr/bin/php artisan backup >> /var/log/site-backup.log 2>&1.
Why your cron job isn't running
When a job doesn't run, check in this order, from the most likely cause to the rarest.
- Is the cron service running?
systemctl status crondon AlmaLinux orsystemctl status cronon Ubuntu should show active (running). - Is cron starting the job at all? On AlmaLinux, look at
/var/log/cron. On Ubuntu and Debian, usegrep CRON /var/log/syslogorjournalctl -u cron. If the job appears in the log, cron is starting it and the problem lies in the command itself. - Run the command by hand in a limited environment.
env -i /bin/sh -c 'your command'runs it almost the way cron does, without your variables. If it fails here, the problem is the paths. - Check the time zone. Cron uses the server's time, not yours. You can see it with
timedatectl. If the server is set to UTC, a job scheduled for 03:00 will run at 04:00 British summer time. - Check the permissions. The job runs with the permissions of the crontab's owner. If a regular user tries to write to a folder owned by root, they'll get Permission denied.
- Read the job's log file. If you've redirected the output, the error is usually written right there.

Overlapping jobs
If a job runs every 5 minutes but sometimes takes 7, the next run will start before the previous one has finished. Two copies of the same script writing to the same files or the same database can cause serious problems.
The solution is flock, which allows only one running copy at a time. The line */5 * * * * /usr/bin/flock -n /tmp/sync.lock /root/scripts/sync.sh skips the new run if the old one is still going.
Automatic backups with cron
One of the most common uses of cron is the nightly backup. This job dumps the database every day at 02:30 and saves a file with the date in its name:
30 2 * * * /usr/bin/mysqldump mydb | gzip > /backups/mydb-$(date +\%F).sql.gz
A second job can delete backups older than 30 days so the disk doesn't fill up: 0 4 * * * find /backups -name "*.sql.gz" -mtime +30 -delete.
Backups kept on the same server aren't real protection, though. If the server fails or is hacked, you lose them too. You can read how to organise backups properly, including the 3-2-1 rule, in our article on website backup.
Cron for WordPress: how to replace WP-Cron
WordPress has its own scheduler, WP-Cron. It handles publishing scheduled posts, checking for updates and running tasks for many plugins. But WP-Cron isn't a real cron: it's only triggered when someone opens a page on the site.
That creates two problems. On a site with few visitors, tasks run late or not on time at all. On a busy site, WP-Cron is checked on every page load and adds unnecessary load.
The fix is to turn off the built-in mechanism and let real cron run it instead:
- Add the line
define('DISABLE_WP_CRON', true);towp-config.php. - Add a crontab job that runs WP-Cron every 5 minutes:
*/5 * * * * cd /var/www/site && /usr/bin/php wp-cron.php > /dev/null 2>&1.
WordPress tasks then run exactly on time, whether or not anyone is visiting the site, and visitors no longer pay the price in speed.

Cron expressions outside Linux
Cron expressions have long been used beyond Linux. The same five-field format sets schedules in Kubernetes CronJobs, GitHub Actions, cloud schedulers and many applications. So if you're looking up what a cron expression means in one of these systems, the rules in this article apply.
There are two differences to watch out for. Some systems, such as Quartz in Java, use six or seven fields, adding seconds at the start and sometimes a year at the end. Cloud services and GitHub Actions usually count time in UTC rather than your local time zone.
Cron vs systemd timers
Modern Linux distributions also offer an alternative: systemd timers. They do the same job as cron but with more features. They keep logs in journalctl, can catch up on a missed run if the server was switched off, and track dependencies between services.
The trade-off is that each job needs two separate files and more configuration. For most everyday tasks, cron remains the simpler and quicker choice. Systemd timers are worth it when a job is critical and you need full control and traceability.

Common mistakes
- Five asterisks by mistake.
* * * * *means every minute. A heavy script scheduled like that can overload the server within minutes. - Forgetting minute 0.
* 3 * * *isn't "at 3 o'clock" but every minute between 03:00 and 03:59, which is 60 times. - No output redirection. Without a log you don't know whether the job succeeded, and cron may pile up emails to the job's owner.
- The server's time differs from yours. The job runs, just not when you expect.
- An unescaped %. The command is cut off at that character and does nothing useful.
- Heavy jobs at peak times. Run backups and image processing at night, when traffic is low.
Frequently asked questions
What is a cron expression?
A cron expression is a string of five fields that sets when a job runs: minute, hour, day of the month, month and day of the week. For example, 0 3 * * * means every day at 03:00.
What does */5 mean in cron?
The slash sets a step. */5 in the minute field means every 5 minutes: at 00, 05, 10 and so on.
How do I see all cron jobs?
You can see your own jobs with crontab -l. As root, you can see another user's jobs with crontab -u name -l. System jobs are in /etc/crontab and /etc/cron.d/.
Do I need to restart cron after a change?
No. When you save a change with crontab -e, cron picks it up automatically.
Can cron run a job every 30 seconds?
Not directly, because cron's smallest unit is one minute. You can add two jobs that run every minute, with the second one starting with sleep 30, or use a systemd timer.
Which time zone does cron use?
The server's time zone. You can check it with timedatectl. Some versions of cron let you set a different zone for specific jobs with the CRON_TZ variable.
Where are the cron logs?
On AlmaLinux and Rocky Linux, in /var/log/cron. On Ubuntu and Debian, entries go to /var/log/syslog or can be read with journalctl -u cron.
Is cron available on shared hosting?
Usually yes, but you access it through the control panel rather than the command line. There you set the same schedule and command in separate fields. On a VPS you have full access to crontab and all the system settings.
Conclusion
Cron is one of the simplest and most useful tools on a Linux server. With five fields you can describe almost any schedule, and the server takes over the routine work: backups, clean-ups, reports and checks. Use full paths, redirect output to a log, check the time zone, and use flock for jobs that mustn't overlap. Do that, and cron will run for years without you having to think about it.
Want a server where you can automate everything? A VPS gives you full root access, crontab and the freedom to run whatever jobs you need. And if you'd rather we looked after the server, choose a managed VPS.


