How to Write a Crontab Entry in Linux

This guide provides a comprehensive overview of the crontab syntax used for scheduling automated tasks in the Linux operating system. It details the five time-and-date fields, explains how to use special operators for advanced scheduling, outlines common shortcut strings, and provides real-world examples to help you configure your cron jobs accurately.

The Basic Crontab Syntax

A standard crontab entry consists of five time-and-date fields followed by the command to execute:

* * * * * command_to_execute
- - - - -
| | | | |
| | | | +----- Day of the week (0 - 6) (Sunday to Saturday, 7 is also Sunday)
| | | +------- Month of the year (1 - 12)
| | +--------- Day of the month (1 - 31)
| +----------- Hour of the day (0 - 23)
+------------- Minute of the hour (0 - 59)

The Five Time Fields

  1. Minute (0 - 59): Specifies the exact minute the command runs.
  2. Hour (0 - 23): Specifies the hour in 24-hour format (e.g., 0 = midnight, 13 = 1 PM).
  3. Day of Month (1 - 31): Specifies the calendar day.
  4. Month (1 - 12): Specifies the month of the year (1 = January, 12 = December).
  5. Day of Week (0 - 7): Specifies the day of the week. Both 0 and 7 represent Sunday.

Special Characters (Operators)

You can use specific operators to define complex scheduling intervals within any field:


Crontab Shorthand Strings

Cron supports predefined shortcuts that can replace the five-field format:


Practical Examples


Managing Crontab Files

Use the crontab utility to manage your user schedule: