Linux / Bash
Beginner
1 min read
Crontab Syntax and Scheduling Jobs
Example
# Edit your user crontab
crontab -e
# List your crontab entries
crontab -l
# Remove your crontab
crontab -r
# Edit another user's crontab (root only)
sudo crontab -u alice -e
# ---- Crontab syntax ----
# m h dom mon dow command
# | | | | |
# | | | | +--- Day of week (0-7, Sun=0 or 7)
# | | | +-------- Month (1-12)
# | | +------------- Day of month (1-31)
# | +----------------- Hour (0-23)
# +-------------------- Minute (0-59)
# Run every minute
# * * * * * /path/to/command
# Run at 2:30 AM every day
# 30 2 * * * /usr/bin/backup.sh
# Run every 15 minutes
# */15 * * * * /usr/bin/health_check.sh
# Run at 8 AM on weekdays (Mon-Fri)
# 0 8 * * 1-5 /usr/bin/morning_report.sh
# Run on the 1st and 15th of every month at midnight
# 0 0 1,15 * * /usr/bin/billing.sh
# Run every Sunday at 3 AM
# 0 3 * * 0 /usr/bin/weekly_cleanup.sh
# Special strings
# @reboot /usr/bin/start_service.sh
# @daily /usr/bin/daily_backup.sh
# @weekly /usr/bin/weekly_task.sh
# @monthly /usr/bin/monthly_report.sh
# @hourly /usr/bin/hourly_check.sh
# Redirect output (cron mails output by default)
# 30 2 * * * /usr/bin/backup.sh >> /var/log/backup.log 2>&1
# Set PATH inside crontab
# PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Related Resources
Linux / Bash Reference
Complete tag & property list
Linux / Bash How-To Guides
Step-by-step practical guides
Linux / Bash Exercises
Practice what you've learned
More in Linux / Bash