System managementIntermediate23 min read

What Does cron Mean?

Reviewed byJohnson Ajibi· Senior Network & Security Engineer · MSc IT Security

This page mentions older exam versions. See the Current Exam Context and Legacy Exam Context sections below for the updated mapping.

On This Page

Quick Definition

Cron lets you schedule tasks to run automatically on a computer at specific times. You write a list of commands with their run times in a file called a crontab. The computer then checks this list every minute and runs any command that matches the current time. This way you don't have to manually start repetitive tasks like backups, updates, or reports.

Common Commands & Configuration

Must Know for Exams

Cron appears in several major IT certification exams, particularly those focused on Linux system administration. For the CompTIA Linux+ (XK0-005), cron is listed under objective 3.1: 'Given a scenario, create, modify, and schedule tasks using cron, at, and systemd timer units.' Expect scenario-based questions where you must interpret a crontab entry, add a new schedule, or troubleshoot why a job is not running. For example, you might be given a requirement like 'run a script called /usr/local/bin/cleanup.sh every Sunday at 2 AM' and asked to choose the correct crontab line from four options.

For the Red Hat Certified System Administrator (RHCSA) exam (EX200), cron is also on the objective list under 'Manage scheduled tasks.' You must be able to create, edit, and delete cron jobs for both users and the system. The exam may ask you to set up a cron job that writes a timestamp to a log file every 5 minutes. Because the RHCSA is a hands-on practical exam, you will actually need to edit a crontab file with the correct syntax and verify that the job executes.

For the LPI Linux Essentials (010-160) and LPIC-1 (101-500/102-500) exams, cron appears as a foundational concept. You should know the role of the cron daemon, the different crontab files (/etc/crontab, /var/spool/cron), and the basic five-field schedule format. Questions may focus on understanding the difference between user crontabs and the system crontab, or what the special directories like /etc/cron.daily are for.

Even the CompTIA A+ 220-1102 exam may touch on cron lightly in the context of macOS or Linux command line fundamentals. While not a major topic, knowing that cron is used for task scheduling can earn you a point on a question about automation tools.

In all these exams, the most common question types are: 'Which crontab entry runs a job at 3:15 PM every Tuesday?' or 'A cron job runs every 30 minutes but should only run once per hour. What is the likely cause?' Expect to see traps involving incorrect field order (minute first, not hour), off-by-one errors (day of week 0 and 7 both mean Sunday), and forgetting to specify a path for the command. Knowing cron thoroughly can easily net you 3-5 correct answers on Linux-focused exams, which can make the difference between passing and failing.

Simple Meaning

Imagine you have a personal assistant who reminds you to water your plants every Monday morning at 9:00. You write down 'Water plants at 9 AM every Monday' on a sticky note and give it to your assistant. The assistant checks the note every minute, and when it's Monday 9:00, they go and water the plants. Cron works exactly like that assistant, but for your computer.

Instead of watering plants, cron runs commands or scripts. For example, you might schedule a script to back up your important files every night at 2 AM. You write the backup command and the schedule (2 AM every day) into a special list called a crontab. The cron service, which is always running in the background of your computer, reads that list every minute. When the computer's clock matches one of the scheduled times in the list, cron executes the corresponding command.

This is extremely useful because computers need to do many routine maintenance tasks automatically. Without cron, a system administrator would have to stay awake at 2 AM to run backups, or manually send weekly reports, or update security patches. Cron handles all of that automatically, freeing up human time and ensuring important tasks never get forgotten. It also runs with the correct system permissions, so it can access files and run commands that a regular user might not be able to.

Cron is not a programming language itself; it is a system service that uses a simple text-based configuration. The schedule is written using five fields that represent minute, hour, day of month, month, and day of week. Each field can be a number, a range, a list, or a special value like an asterisk that means 'every'. For instance, '0 2 * * *' means 'run at 2:00 AM every day'. This syntax may look strange at first, but once you learn the pattern, it becomes a powerful tool for automation.

Full Technical Definition

Cron is the standard time-based job scheduler on Unix-like operating systems, including Linux, macOS, and various BSD distributions. It is implemented as a daemon process (crond) that wakes up every minute, reads the crontab files for every user, and determines whether any scheduled jobs should be executed. The term 'cron' is derived from the Greek word 'chronos' meaning time.

Cron works with crontab (cron table) files. Each user has their own crontab file, typically stored in /var/spool/cron/crontabs/ on Linux systems or /var/cron/tabs/ on some Unix variants. The system also has a system crontab in /etc/crontab and directories like /etc/cron.d/ for additional scheduled tasks. The syntax for a crontab entry consists of six space-separated fields: minute (0-59), hour (0-23), day of month (1-31), month (1-12), day of week (0-7, where both 0 and 7 represent Sunday), and the command to be executed. Fields can be an asterisk (*) for 'every possible value', a comma-separated list (e.g., 1,15,30), a range (e.g., 9-17), a step value (e.g., */5 for every 5 units), or a combination.

In a real IT environment, cron is used for automating system maintenance tasks such as rotating log files, compressing old data, running security scans, performing database backups, updating system packages, emailing reports, and synchronizing with external services. System administrators often write shell scripts and place them in cron-controlled directories like /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, and /etc/cron.monthly. These directories are managed by run-parts, which executes every executable script found in the named directory.

Cron does not handle jobs that run longer than the interval between schedules. For example, if a job is scheduled to run every hour but takes two hours to complete, a second instance could start before the first finishes. This can cause resource contention or data corruption. To prevent this, administrators use mechanisms like flock, lock files, or wrapper scripts that check whether the job is already running. Also, cron does not capture or manage environmental variables in the same way as a user's interactive shell, so scripts run under cron often fail because they lack PATH, HOME, or other variables. Best practice is to set important environment variables at the top of the crontab file or within the script itself.

Cron logging is essential for troubleshooting. On most systems, cron logs its actions to /var/log/cron or through syslog. The log shows each time a job is started, finished, or if there was an error. By default, cron sends any output (stdout) from a job to the user's local email if no redirection is specified. In production environments, output is usually redirected to a file or to /dev/null to prevent inbox clutter.

Modern alternatives like systemd timers in Linux have gained popularity because they offer more features like persistent timers after missed runs, dependencies on other services, and detailed logging. However, cron remains widely used due to its simplicity, ubiquity, and decades of proven reliability. Understanding cron is fundamental for any system administrator or IT professional working with Unix-like systems.

Real-Life Example

Think of a busy restaurant kitchen. The head chef has a list of tasks that need to happen at certain times every day. For instance, the prep cook must chop vegetables every day at 6:00 AM. The sous chef must taste the soup every four hours starting at 10:00 AM. The dishwasher must run the machine every night at 11:00 PM. Instead of the head chef running around reminding everyone, they write these times and tasks on a whiteboard in the kitchen. A reliable kitchen timer beeps every minute, and whenever the current time matches a task on the board, the person responsible does that task automatically.

In this analogy, the head chef is the system administrator, the whiteboard is the crontab file, and the kitchen timer that beeps every minute is the cron daemon. The prep cook chopping vegetables at 6:00 AM is like a cron job that runs a backup script every morning. The sous chef tasting soup every four hours is like a monitoring script that checks server health. The dishwasher running at 11:00 PM is like a cleanup script that deletes temporary files.

Now imagine that one day the prep cook is sick. The head chef doesn't know, so the vegetables don't get chopped until the head chef notices and does it manually. In cron terms, this is like your scheduled script failing because the server was off or the script had an error. Cron does not automatically retry failed jobs or notify someone unless you configure email or logging. Just like in the kitchen, you need a system to check that tasks are completed.

Also, if the head chef writes 'wash dishes every hour' but the dishwasher takes 90 minutes, two dishwasher cycles would overlap and break the machine. That is exactly what happens when a cron job takes longer than its interval. So you would correct the schedule to allow enough time, or use a lock file to prevent overlapping runs.

This analogy shows how cron takes the mental load off humans and creates reliable automation, but also why you need to think carefully about durations, dependencies, and monitoring.

Why This Term Matters

In the real world of IT, servers and systems must run 24/7 with minimal human intervention. Cron is one of the simplest and most reliable tools to achieve that. Without cron, system administrators would have to either stay up all night running maintenance tasks or rely on complex commercial scheduling software. Cron gives every IT professional a free, built-in automation engine that works on almost any Unix-like system.

Cron matters because it helps enforce discipline and consistency. When you schedule a backup with cron, that backup happens exactly when you said it would, every single time, without fail. This is critical for compliance with data protection policies and service level agreements. Many organizations require daily backups, weekly system updates, and hourly log rotations. Cron makes these requirements achievable without needing a dedicated person to push buttons.

Cron also matters in DevOps and continuous integration workflows. Developers use cron to trigger automated tests every night, deploy code to staging servers on a schedule, or clear caches during low-traffic hours. Even cloud environments like AWS use cron-like scheduling for Lambda functions or CloudWatch events. Understanding cron gives you a transferable skill that applies to many platforms.

From a career perspective, cron is a frequent topic in job interviews for system administration roles. Interviewers ask about crontab syntax, how to debug cron jobs, and how to handle common failures. If you cannot set up a cron job correctly, you will not be trusted with production servers. Also, cron is often the first automation tool a junior admin learns, and mastering it builds confidence for more advanced configuration management tools like Ansible, Puppet, or Chef.

Finally, cron matters because it is still used in the majority of Linux servers worldwide. Despite newer alternatives, cron is lightweight, simple, and well-documented. Knowing cron means you can work on legacy systems as well as modern ones. It is a foundational skill that every IT professional should have in their toolbox.

How It Appears in Exam Questions

Cron appears in certification exam questions in several predictable patterns. The most common is the 'schedule interpretation' question. You are given a crontab entry like '30 3 * * 1 /usr/bin/backup.sh' and asked what it does. The correct answer is 'Runs backup.sh every Monday at 3:30 AM.' Distractors often include 'runs at 3:30 PM on the 30th of every month' (confusing minute and hour) or 'runs at 3:30 on the 1st of every month' (confusing day of week 1 with day of month). You must remember that the fields are always in order: minute, hour, day of month, month, day of week.

Another question type is 'add a cron job' or 'choose the correct crontab entry for a given schedule'. For example, 'Schedule a job to run at 2:15 PM on the 15th of every month.' The correct answer would be '15 14 15 * * /path/to/command'. Notice the hour is 14 (2 PM) because cron uses 24-hour time. A common distractor is to write '15 2 15 * *' which runs at 2:15 AM, not PM.

Scenario-based questions are also common. For example, 'A system administrator notices that a cron job that runs every hour is sometimes still running when the next instance starts. What should the administrator do?' The correct action is to use a lock file or a wrapper script that checks if the script is already running. Other options might include 'increase the scheduling interval' (which does not solve the overlap) or 'use a shorter script' (not always possible).

Troubleshooting questions might say: 'A cron job that emails a report is not running. The crontab entry looks correct. What is the most likely cause?' Possible answers include: the cron daemon is not running, the script has no execute permission, the script's path is not fully qualified, or the output is not captured. These questions test your understanding that cron runs with a minimal shell environment and does not inherit user PATH or environment variables.

Finally, there are multiple-choice questions about cron's behavior: 'What happens if a cron job produces output but is not redirected?' Answer: 'The output is emailed to the owner of the crontab.' This is a classic exam fact. Knowing such details helps you eliminate wrong answers quickly.

In performance-based exams (like RHCSA), you might be given a scenario where you must actually edit a user's crontab using 'crontab -e', add a job, and then verify it ran by checking logs in /var/log/cron or by creating a timestamp file. These hands-on questions require you to recall syntax without any help, so memorizing the field order and common schedule patterns is essential.

Study CompTIA Linux+

Test your understanding with exam-style practice questions.

Practise

Example Scenario

You are a junior system administrator at a small company. The company uses a Linux server to host their website and a customer database. Every night at 11:30 PM, the server must create a compressed backup of the database file /var/lib/mysql/customers.db and save it to /backups/db_backup_$(date +%Y%m%d).tar.gz. The backup script also needs to delete any backup files older than 30 days to save disk space.

Your manager asks you to set up a cron job to automate this backup. You log into the server via SSH. First, you test the backup command manually to ensure it works. You create a simple shell script called /usr/local/bin/backup_db.sh that contains the tar command and the cleanup logic. You make the script executable with chmod +x /usr/local/bin/backup_db.sh.

Next, you need to schedule it. You run crontab -e to edit your user's crontab. The schedule must be 11:30 PM every day. In 24-hour time, 11:30 PM is 23:30. The day of month, month, and day of week should all be asterisks because it runs every day. The crontab line looks like: '30 23 * * * /usr/local/bin/backup_db.sh'.

You save and exit the editor. Cron should automatically reload the crontab. To verify, you check the list of active cron jobs with crontab -l. The entry appears as expected. You wait until the next minute and check /var/log/cron to see if cron recognized the job. The log shows 'CRON[1234]: (username) CMD (/usr/local/bin/backup_db.sh)'.

However, the next morning you check /backups and find no backup file. You then look at the cron log more carefully and see a line: 'CRON[1234]: (username) MAIL (mailed 1 byte of output)'. This indicates the script ran but produced some output, which was emailed. You check your local mail and see error messages: the tar command could not access the database file because the cron job runs as your user, not as the database owner. Your user does not have read permission on /var/lib/mysql/customers.db.

You fix this by either adding your user to the mysql group, or by running the cron job as root using sudo crontab -e. You choose the root crontab because it is simpler. The next night the backup runs successfully. You verify by listing /backups and seeing the compressed file. This scenario shows the real steps: testing manually, writing the crontab, verifying with logs, troubleshooting permissions, and using root for system tasks.

Common Mistakes

Writing the crontab fields in the wrong order

The fields must be exactly minute, hour, day of month, month, day of week. If you put hour first, the job runs at a completely wrong time.

Always memorize the order: Minute, Hour, Day, Month, Weekday. Use a mnemonic like 'Minute Hour Day Month Weekday'.

Using 12-hour time instead of 24-hour time

Cron uses a 24-hour clock. Entering '12' for midnight is correct but '12' for noon is also correct. Confusing AM and PM leads to jobs running at the wrong time of day.

Always convert to 24-hour time. For example, 2:00 PM is 14, 11:30 PM is 23, midnight is 0.

Forgetting to specify the full path to the command

Cron runs with a minimal environment and may not have the same PATH as your interactive shell. If the script or command is not found, the job fails silently.

Always use the absolute path to the executable, e.g., /usr/bin/find instead of just find. Also set PATH at the top of the crontab if needed.

Not redirecting output and expecting it to vanish

Cron sends any stdout or stderr to the user's local mail unless redirected. This can fill up the mailbox or cause confusion when output is unintentional.

Append '> /dev/null 2>&1' to the end of the cron job command if you do not want to see output. Or redirect to a log file: '>> /var/log/myjob.log 2>&1'.

Assuming cron jobs automatically retry on failure

Cron does not retry failed jobs. If a script fails due to a temporary resource issue, it will not run again until the next scheduled time.

Implement retry logic inside the script itself, or use a monitoring tool to alert when a cron job fails.

Exam Trap — Don't Get Fooled

{"trap":"A question shows a crontab entry: '0 0 * * 0 /usr/bin/backup.sh' and asks what day the job runs. Many learners think it runs on the first day of the month because of the '0' in the day-of-week field."

,"why_learners_choose_it":"Learners confuse day-of-week '0' (Sunday) with day-of-month '1' (first day). Seeing a '0' in the fifth field triggers the assumption that it means 'first day'.","how_to_avoid_it":"Memorize that day of week uses 0 and 7 for Sunday, 1 for Monday, etc.

Day of month starts at 1. The entry '0 0 * * 0' means 12:00 AM (midnight) every Sunday. Always double-check field positions."

Commonly Confused With

cronvssystemd timers

Systemd timers are a newer alternative to cron on Linux systems that provide more features like persistent timers (run after missed boot), calendar events with natural language syntax, and dependency on other services. Cron is simpler but does not guarantee a missed job will run later.

With a systemd timer, you can say 'OnCalendar=Mon..Fri 09:00:00' and it will handle daylight saving time better. With cron, you write '0 9 * * 1-5' for weekdays at 9 AM.

cronvsat command

The 'at' command schedules a one-time job at a specific time, whereas cron schedules recurring jobs. 'at' is for 'run this once next Tuesday at 3 PM', while cron is for 'run this every Tuesday at 3 PM'.

If you need to run a script at 5:00 PM today only, use 'at 17:00'. If you need it to run at 5:00 PM every day, use cron.

cronvsanacron

Anacron is designed for systems that are not running 24/7, like laptops. It ensures that jobs scheduled daily, weekly, or monthly run even if the system was powered off during the scheduled time. Cron assumes the system is always on and will miss jobs if the system is down.

Your laptop is turned off at 2 AM when the backup cron job is scheduled. Anacron would run the backup when you turn the laptop on later that day. Cron would simply skip that job.

Step-by-Step Breakdown

1

Determine the schedule and command

Decide exactly when the job should run (e.g., every Monday at 3:00 AM) and what command or script to execute. Write down the full path to the script, e.g., /home/user/scripts/cleanup.sh. This step is crucial because errors in schedule or command will cause the job to fail or run at wrong times.

2

Open the crontab file for editing

Run 'crontab -e' as the user who should own the job. This opens the user's crontab in the default text editor (usually vi or nano). For system-wide jobs, you edit /etc/crontab directly using sudo. This step ensures the job runs with the correct permissions.

3

Write the cron entry using the correct syntax

Add a line with five time fields followed by the command. For example: '0 3 * * 1 /home/user/scripts/cleanup.sh'. Each field is space-separated. Use asterisks for 'every' and commas for lists. This is the core of cron configuration; a typo here breaks the schedule.

4

Save and exit the editor

The crontab file is automatically installed by the crontab command. Cron detects the file change and reloads the configuration. No restart of the cron daemon is needed. This step finalizes the schedule.

5

Verify the cron entry

Run 'crontab -l' to list all cron jobs for the current user. Confirm the entry is correct. You can also check the cron log (usually /var/log/cron) to see if cron acknowledges the job. This step catches syntax errors or missing entries.

6

Test and monitor the job

Wait for the scheduled time or manually check if the job runs. Check the output log or the cron log for any error messages. Verify the desired outcome (e.g., backup file created). This step ensures the job actually works in the real environment.

Practical Mini-Lesson

Cron is one of the most fundamental tools for automation in Linux system administration, but it requires careful attention to detail. Let's walk through a real-world configuration that a professional might use.

First, understand that cron syntax uses five time fields. They are, in order: minute (0-59), hour (0-23), day of month (1-31), month (1-12), and day of week (0-7, 0 and 7 both meaning Sunday). An asterisk means 'every'. For example, '30 4 * * 1-5' means 'at 4:30 AM, Monday through Friday.' Ranges use hyphens: '1-5' for weekdays. Lists use commas: '0,30' for half-hour intervals. Step values use */n: '*/15' in the minute field means 'every 15 minutes'.

When writing a crontab entry, always use absolute paths for commands. For example, instead of 'tar -czf /backup/backup.tar.gz /data', write '/usr/bin/tar -czf /backup/backup.tar.gz /data'. This avoids issues with PATH. Also, it is good practice to redirect output. Append '>/dev/null 2>&1' to discard all output, or '>>/var/log/myjob.log 2>&1' to append to a log file. If you do not redirect, cron will email the output, which can clutter your mailbox.

A common professional pattern is to use a wrapper script. Instead of putting a long command directly in the crontab, write a shell script that does all the work, including logging, error handling, and environment setup. Then in the crontab, just call that script. This makes it easier to test the script manually and debug failures.

Another important detail: cron does not load your .bashrc or .profile. If your script depends on environment variables like JAVA_HOME or database passwords, you must set them inside the script or at the top of the crontab file. For example: 'PATH=/usr/local/bin:/usr/bin:/bin' or 'MY_VAR=value' on a line before the job entry.

Permissions are also critical. The user who owns the crontab must have execute permission on the script and read/write access to any files or directories the script touches. For system-level jobs, it is common to use the root crontab (sudo crontab -e) because root has full access. However, be careful: running jobs as root can be dangerous if the script has bugs, as it can damage the entire system.

Finally, monitor your cron jobs. Check /var/log/cron for entries like 'CMD' (command executed) or 'REPLACE' (crontab updated). If a job fails, the log will show an error or a mail notification. Use a simple health check script that runs via cron and alerts you if a previous job did not run successfully. This proactive approach prevents silent failures that could lead to data loss or service outages.

Troubleshooting Clues

Symptom:

Symptom:

Symptom:

Symptom:

Symptom:

Symptom:

Memory Tip

Remember the field order with the mnemonic: 'March, Hour, Day, Month, Weekday' but replace 'March' with 'Minute', so it's 'Minute Hour Day Month Weekday'.

Covered in These Exams

Current Exam Context

Current exam versions that test this topic — use these objectives when studying.

Legacy Exam Context

Older materials may mention these exam versions, but learners should use the current objectives for their target exam.

XK0-005XK0-006(current version)

Related Glossary Terms

Quick Knowledge Check

1.Which crontab entry runs a job at 5:30 PM every Friday?

2.What is the default action for output from a cron job?

3.The crontab field order is:

4.Why might a cron job fail even though the command works in the terminal?

Frequently Asked Questions

How do I edit my crontab for the first time?

Run the command 'crontab -e' in the terminal. It will open your crontab file in the default text editor (usually vi or nano). Add a line with the schedule and command, then save and exit.

What happens if I make a syntax error in my crontab?

When you save and exit, the crontab command will reject the file and show an error message. Your existing crontab will remain unchanged, so you will not lose previous jobs.

Can I schedule a job to run every 10 seconds?

Cron has a minimum granularity of 1 minute. For sub-minute scheduling, you would need to use a different tool like systemd timers with OnCalendar=*:0/10 or write a loop in your script with sleep commands.

How do I redirect cron job output to a file?

Append '>> /path/to/logfile.log 2>&1' to the end of your command. This appends standard output and standard error to the log file.

What does the % symbol mean in a crontab entry?

In a crontab entry, a percent sign (%) is treated as a newline. It is used to pass multiple lines of input to a command, but it must be escaped as \% if you want a literal percent.

Why is my cron job not running? I checked the log and it says '(user) CMD (command)' but nothing happens.

The log line indicates that cron did try to run the command. Most likely the command itself failed. Test the exact command from the crontab manually in the shell. Also check the script's permissions and that any required environment variables are set.