How to Schedule Tasks with Cron on Linux
Learn crontab syntax and set up automated, recurring tasks on Linux — from daily backups to hourly scripts.
What Is Cron?
Cron is Linux's built-in job scheduler. It runs commands or scripts automatically at times you define — every minute, every day at 3 AM, the first of every month, or any schedule you can imagine. It is the go-to tool for automating backups, log rotation, syncing files, and any repetitive task.
Editing Your Crontab
Each user has their own crontab (cron table). Edit it with:
crontab -e
This opens your crontab in the default editor. Each line is one scheduled job.
Crontab Syntax
Every cron line has five time fields followed by the command:
# ┌───────────── minute (0–59)
# │ ┌─────────── hour (0–23)
# │ │ ┌───────── day of month (1–31)
# │ │ │ ┌─────── month (1–12)
# │ │ │ │ ┌───── day of week (0=Sun, 6=Sat)
# │ │ │ │ │
# * * * * * command-to-run
Use * to mean "every". Use commas for lists (1,15), hyphens for ranges (1-5), and slashes for intervals (*/10 = every 10).
Common Schedule Examples
# Every day at 2:30 AM
30 2 * * * /home/alice/backup.sh
# Every hour
0 * * * * /usr/bin/python3 /home/alice/sync.py
# Every 10 minutes
*/10 * * * * /home/alice/check.sh
# Every Monday at 9 AM
0 9 * * 1 /home/alice/weekly-report.sh
# First day of every month at midnight
0 0 1 * * /home/alice/monthly-cleanup.sh
Handy Shortcuts
Cron also supports these readable aliases:
@reboot— run once at startup@hourly— equivalent to0 * * * *@daily— equivalent to0 0 * * *@weekly— equivalent to0 0 * * 0@monthly— equivalent to0 0 1 * *
Viewing and Managing Cron Jobs
# List your cron jobs
crontab -l
# Remove all your cron jobs (careful!)
crontab -r
Tips for Reliable Cron Jobs
- Use absolute paths for commands and files — cron has a minimal environment
- Redirect output to a log:
command >> /var/log/myjob.log 2>&1 - Test your script manually before scheduling it
- Use crontab.guru to verify your schedule expressions