Linux Basic — crontab Syntax

less than 1 minute read

crontab Syntax

A crontab entry has five time fields followed by the command to run.

# ┌───────────── minute (0–59)
# │ ┌───────────── hour (0–23)
# │ │ ┌───────────── day of month (1–31)
# │ │ │ ┌───────────── month (1–12)
# │ │ │ │ ┌───────────── day of week (0–7, 0 and 7 = Sunday)
# │ │ │ │ │
# * * * * * command-to-execute

Examples

# every minute
* * * * * /opt/check.sh

# daily at 2:30 AM
30 2 * * * /opt/backup.sh

# every Monday at 9 AM
0 9 * * 1 /opt/weekly-report.sh

# first day of every month at midnight
0 0 1 * * /opt/monthly-cleanup.sh

Field Values

Field Range Special
minute 0–59  
hour 0–23  
day 1–31  
month 1–12 or jan–dec
weekday 0–7 0 and 7 = Sun, or sun–sat

* means “every value” for that field.


Common Pitfalls

  • Both day and weekday specified → cron runs if either matches (OR, not AND)
  • Percent signs (%) in the command are interpreted as newlines — escape with \%
  • Environment is minimal — no $PATH from your shell, no aliases

Next → cron Expressions

Updated: