What Is a Cron Job and How Do You Use It?
Ever wonder how servers run automated tasks like nightly backups? Learn what a cron job is, how the syntax works, and how to schedule your own tasks on Linux.
Publish date: 12/2/2025
Ever wonder how servers run automated tasks like nightly backups? Learn what a cron job is, how the syntax works, and how to schedule your own tasks on Linux.
Publish date: 12/2/2025
If you've ever managed a server, you've probably faced tasks you need to run on a schedule. Maybe you need to clear out temporary files every night, send a report every Monday morning, or run a backup script at 3 AM. You certainly don't want to wake up at 3 AM just to type a command.
This is where cron comes in.
Cron is a time-based job scheduler found in Unix-like operating systems, including Linux. It's a small, efficient daemon (a background process) that wakes up every minute, checks a list of instructions, and runs any tasks that are scheduled for that exact time.
These scheduled tasks are called "cron jobs," and they are the secret behind most automated server maintenance. For system administrators and developers, it's one of the most fundamental tools for automation.
The cron system has two main parts.
cron daemon: This is the service itself, running in the background. You can usually check its status with a command like systemctl status cron. It's the engine that actually executes the jobs.crontab: This is short for "cron table." A crontab is a simple text file that contains the list of jobs and the times they should run. Each user on the system can have their own crontab file, and there's also a system-wide crontab (usually at /etc/crontab) for system-level tasks.When you want to schedule a task, you don't edit a random file; you use a special command to safely edit your personal crontab.
Scheduling a cron job involves learning two things: the command to edit the table and the syntax to define the time.
To work with your crontab, you'll use the crontab command in your terminal:
crontab -e: This is the command to edit your crontab. The first time you run this, it might ask you to pick a default text editor (like nano or vim).crontab -l: This command lists all the cron jobs currently in your crontab, letting you see what's scheduled.crontab -r: This command removes your entire crontab. Be very careful with this one!When you run crontab -e, you'll open a text file. Each line in this file represents one cron job and consists of two parts: the time schedule and the command to run.
The time schedule is defined by five "fields," often represented as five asterisks:
* * * * * /path/to/your/command
Here is what each field means, in order from left to right:
An asterisk (*) is a wildcard, meaning "every" or "all." So, * * * * * means "every minute of every hour of every day of every month of every day of the week."
You can also use other operators:
,): Separates a list of values. (e.g., 0,15,30,45 in the minute field means "at :00, :15, :30, and :45").-): Defines a range. (e.g., 1-5 in the day of week field means "Monday through Friday")./): Specifies step values. (e.g., */15 in the minute field means "every 15 minutes").Let's put it all together.
Run a backup script every night at 2:30 AM:
30 2 * * * /home/user/scripts/backup.sh
Run a report script every Monday at 9:00 AM:
0 9 * * 1 /home/user/scripts/run-report.py
Run a cleanup task on the 1st and 15th of every month at midnight:
0 0 1,15 * * /usr/bin/find /tmp -type f -delete
Run a command every 10 minutes:
*/10 * * * * /home/user/scripts/check-something.sh
Most modern cron implementations also support special strings that are easier to read:
@reboot: Runs once at startup.@hourly: Same as 0 * * * *.@daily: Same as 0 0 * * *.@weekly: Same as 0 0 * * 0.@monthly: Same as 0 0 1 * *.So, instead of 0 0 * * *, you can just write:
@daily /home/user/scripts/cleanup.sh
For a complete breakdown of all possible syntax options, the official crontab manual page is an excellent resource.
Cron is the daemon, or the service, that runs in the background. Crontab is the file, or table, that lists the jobs for cron to run. You edit the crontab to tell cron what to do.
The best way is to check the logs. You can either log the output of your script to a file (as shown above) or check the system logs. On many systems, cron logs its activity to /var/log/syslog or /var/log/cron. You can check this with a command like grep CRON /var/log/syslog.
No. Cron's lowest time resolution is one minute. If you need sub-minute scheduling, you'll need a different approach. A common alternative on modern Linux systems is using a systemd timer, which offers more flexibility. You can read more about the differences in our systemd vs. cron comparison.
You should almost always use crontab -e to edit it. This prevents syntax errors and ensures the cron daemon is notified of changes. But if you're curious, individual user crontabs are typically stored in /var/spool/cron/crontabs/.
For Linux users, especially system administrators, cron is an essential tool. It's the standard, lightweight, and reliable way to automate repetitive tasks, saving you time and letting you "set it and forget it." Learning its syntax might take a few tries, but it's a fundamental skill for managing any server.
Thanks for reading! If you're looking for reliable infrastructure to run your tasks, xTom provides enterprise-grade dedicated servers and colocation services, while V.PS offers scalable, production-ready NVMe-powered VPS hosting perfect for any workload. We also offer IP transit, shared hosting, and other IT services.
Ready to discuss your infrastructure needs? Contact our team to explore the right solution for your projects.