Console9

Crontab expression reference

Complete reference for crontab time expression fields, special strings, and environment variables with working examples.

Complete reference for crontab scheduling syntax, including the five time fields, special characters, shorthand strings, and environment variables.

Crontab Time Expression Fields

The crontab time expression consists of five fields that define when the cron daemon executes a job. Each field accepts integers, ranges, lists, and step values.

┌───────────── minute (0–59)
│ ┌───────────── hour (0–23)
│ │ ┌───────────── day of month (1–31)
│ │ │ ┌───────────── month (1–12)
│ │ │ │ ┌───────────── day of week (0–7, where 0 and 7 both represent Sunday)
│ │ │ │ │
* * * * * command
FieldCrontab field nameAllowed valuesDescription
1Minute059Crontab triggers the job when the system clock minute matches this value
2Hour023Crontab uses 24-hour format; 0 is midnight, 13 is 1:00 PM
3Day of month131Crontab runs the job on this calendar day; values beyond the month's last day are skipped
4Month112 or jandecCrontab accepts numeric or three-letter abbreviated month names
5Day of week07 or sunsatCrontab treats both 0 and 7 as Sunday; accepts three-letter abbreviated day names

Crontab Special Characters

The crontab expression parser supports four special characters within any time field.

CharacterCrontab meaningExampleResult
*Crontab matches every possible value for the field* * * * *Crontab runs the job every minute of every hour of every day
,Crontab matches a list of specific values0,15,30,45 * * * *Crontab runs the job at minute 0, 15, 30, and 45 of every hour
-Crontab matches a contiguous range of values0 9-17 * * *Crontab runs the job at the top of every hour from 9:00 AM to 5:00 PM
/Crontab matches at step intervals within a range*/10 * * * *Crontab runs the job every 10 minutes (minute 0, 10, 20, 30, 40, 50)

Crontab Common Schedule Examples

The crontab expression syntax combines the five time fields into schedules. These are the most frequently used crontab patterns.

Crontab expressionSchedule descriptionUse case
0 * * * *Crontab runs the job at minute 0 of every hourHourly health checks, log aggregation
0 2 * * *Crontab runs the job at 2:00 AM every dayNightly database backups, report generation
*/5 * * * *Crontab runs the job every 5 minutesService monitoring, uptime checks
0 0 * * 0Crontab runs the job at midnight every SundayWeekly maintenance tasks, full backups
0 0 1 * *Crontab runs the job at midnight on the first day of every monthMonthly reports, invoice generation
30 4 * * 1-5Crontab runs the job at 4:30 AM Monday through FridayWeekday-only batch processing
0 */6 * * *Crontab runs the job every 6 hours (at 0:00, 6:00, 12:00, 18:00)Certificate renewal checks, cache purging
0 9 * * 1Crontab runs the job at 9:00 AM every MondayWeekly team reports

Crontab Special Shorthand Strings

The crontab parser on most Linux distributions accepts shorthand strings in place of the five-field expression. These crontab shortcuts replace the entire time specification.

Crontab shorthandEquivalent expressionSchedule description
@rebootN/ACrontab runs the job once when the system boots; does not repeat
@yearly0 0 1 1 *Crontab runs the job at midnight on January 1
@monthly0 0 1 * *Crontab runs the job at midnight on the first day of each month
@weekly0 0 * * 0Crontab runs the job at midnight every Sunday
@daily0 0 * * *Crontab runs the job at midnight every day
@hourly0 * * * *Crontab runs the job at minute 0 of every hour

Crontab Environment Variables

The crontab file accepts environment variable assignments before the job entries. The cron daemon applies these variables to all jobs that follow the assignment.

VariableCrontab behaviorDefaultExample
PATHCrontab uses this value to locate executables in job commands/usr/bin:/binPATH=/usr/local/bin:/usr/bin:/bin
SHELLCrontab uses this shell to execute job commands/bin/shSHELL=/bin/bash
MAILTOCrontab sends job output as email to this address; set to "" to suppress emailOwner's local mailboxMAILTO=admin@example.com
CRON_TZCrontab evaluates time expressions in this timezone instead of the system timezoneSystem timezoneCRON_TZ=America/New_York
HOMECrontab uses this directory as the working directory for job commandsOwner's home directoryHOME=/opt/app

Crontab File Format

A complete crontab file combines environment variables and job entries. The cron daemon reads the file from top to bottom and applies variables to all subsequent jobs.

# Crontab environment variables
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=admin@example.com

# Crontab job entries
0 2 * * * /home/user/scripts/backup.sh >> /home/user/logs/backup.log 2>&1
*/5 * * * * /home/user/scripts/healthcheck.sh >> /home/user/logs/health.log 2>&1
@reboot /home/user/scripts/startup.sh

The crontab file must end with a newline character. The cron daemon ignores the last line if it does not end with a newline — this is a common cause of crontab jobs not running.