Crontab Guide: Format, Syntax, and Configuration in Linux

“Crontab” stands for “Cron Table.” It is simply a text file that contains a list of commands meant to be run at specified times.

While Cron is the system daemon (background process) that actually executes tasks, the crontab is the configuration interface where you define what to run and when to run it. If you are looking to automate server maintenance, backups, or script execution on a Linux environment, this file is your control center.

What is the Purpose of a Crontab?

The primary purpose of a crontab is to bridge the gap between your specific requirements and the operating system’s Cron daemon.

In a Unix-like operating system (such as Linux or macOS), every user can have their own crontab file. This file tells the system exactly when to wake up and execute a specific command or script. Once the command is executed, the daemon goes back to sleep until the next scheduled interval occurs.

Whether you are a sysadmin managing server health or a developer scheduling automated emails, the crontab is where those rules live.

The Anatomy of a Crontab Line

Understanding the crontab format is crucial because a single syntax error can prevent your jobs from running.

Every active line in a crontab follows a strict structure consisting of two main components: the cron schedule and the command.

Here is the general syntax:

* * * * * /path/to/command/or/script.sh

The Cron Schedule Expression

The first part of the line consists of five fields (often represented by asterisks (*)). These fields determine the timing of the job.

The five fields represent, in order:

  1. Minute (0 – 59)
  2. Hour (0 – 23)
  3. Day of the Month (1 – 31)
  4. Month (1 – 12)
  5. Day of the Week (0 – 6)

For a deep dive into how to manipulate these stars to create complex schedules (like “every 5 minutes” or “every Monday at 3 AM”), check out our guide on the Cron Expression.

The Command to Execute

The second part of the line is the shell command itself. This is exactly what you would type into your terminal if you were running the task manually.

A note on file paths: One common mistake when defining a crontab linux entry is relying on relative paths. When cron runs, it executes in a minimal environment, meaning it might not know where your script lives or where your coding language is installed.

Always use absolute paths for both the engine and the script.

Bad:

python script.py

Good:

/usr/bin/python3 /home/user/projects/automation/script.py

How to Edit Crontab in Linux

You should generally avoid editing crontab files directly in the text editor (like opening /var/spool/cron/crontabs/root manually). Doing so can corrupt the file or cause permission issues.

Instead, use the built-in CLI tools provided by the cron package.

To edit crontab for the current user, run:

crontab -e

This opens your default text editor (usually Nano or Vim). When you save and close this file, cron automatically checks the syntax and installs the new crontab.

To view your current list of scheduled jobs without editing them, run:

crontab -l

Practical Crontab Examples

Here are a few real-world examples to help you visualize a valid cron schedule format.

1. Run a backup script every day at midnight

0 0 * * * /home/user/scripts/backup.sh

2. Run a PHP script every 15 minutes

*/15 * * * * /usr/bin/php /var/www/html/cron.php

3. Run a job at 8:30 AM on weekdays only

30 8 * * 1-5 /home/user/scripts/morning_report.sh

Tools for Creating Crontabs

Memorizing the position of every asterisk in the cron schedule can be tedious, and making a mistake is easy. Fortunately, there are excellent tools available to help you generate the correct syntax without the guesswork.

  • Crontab.cronhub.io – A visual generator that helps you edit crontab syntax easily.
  • Crontab.guru – A quick editor for checking the meaning of a specific cron expression.

Using these tools ensures your syntax is valid before you paste it into your server configuration.

Monitor now. For free.