1. Understand the basics
crontab is the tool used to schedule recurring tasks (jobs) on Linux systems. Each user has their own crontab file.
2. List current cron jobs
crontab -l
- If no jobs exist, it will show “no crontab for ” or an empty output.
3. Edit your crontab
crontab -e
- The first time you run this, it will ask you to choose an editor (nano, vim, etc.).
- This opens your personal crontab file for editing.
4. Crontab syntax (6 fields)
MINUTE HOUR DOM MONTH DOW COMMAND
0-59 0-23 1-31 1-12 0-7 /path/to/command or script
| Field | Allowed values | Special characters |
|---|---|---|
| Minute | 0–59 | , – * / |
| Hour | 0–23 | , – * / |
| Day of month | 1–31 | , – * / ? L W |
| Month | 1–12 or JAN–DEC | , – * / |
| Day of week | 0–7 (0 and 7 = Sun) | , – * / ? L # |
| Command | Full path required |
5. Common examples
| Schedule | Crontab line |
|---|---|
| Every minute | * * * * * /path/to/script.sh |
| Every 5 minutes | */5 * * * * /path/to/script.sh |
| Every day at 3:30 AM | 30 3 * * * /path/to/backup.sh |
| Every Monday at 6:00 AM | 0 6 * * 1 /path/to/weekly-report.sh |
| Every day at 00:00 | 0 0 * * * /path/to/daily-task.sh |
| Twice a day (8 AM & 8 PM) | 0 8,20 * * * /path/to/script.sh |
| First day of every month | 0 2 1 * * /path/to/monthly.sh |
| Reboot | @reboot /path/to/startup-script.sh |
| Yearly | @yearly /path/to/annual-task.sh (same as 0 0 1 1 *) |
6. Best practices
- Always use absolute paths for commands and scripts:
/usr/bin/python3 /home/user/myscript.py
- Redirect output to avoid mail spam:
*/10 * * * * /home/user/backup.sh >> /var/log/backup.log 2>&1
or silence completely:
*/10 * * * * /home/user/backup.sh > /dev/null 2>&1
7. System-wide cron jobs (requires root)
System cron files are located in:
/etc/crontab/etc/cron.d//etc/cron.hourly/,/etc/cron.daily/,/etc/cron.weekly/,/etc/cron.monthly/
Example /etc/crontab line:
15 4 * * * root /usr/local/bin/system-maintenance.sh
8. Useful commands summary
| Command | Purpose |
|---|---|
crontab -l | List your cron jobs |
crontab -e | Edit your cron jobs |
crontab -r | Remove all your cron jobs |
sudo crontab -u user -e | Edit another user’s crontab (as root) |
sudo systemctl status cron | Check if cron daemon is running |
9. View cron logs (location varies by distro)
# Ubuntu/Debian
journalctl -u cron -f
# RHEL/CentOS/Fedora (older)
grep CRON /var/log/syslog
# or
grep CRON /var/log/cron
# Many systems
sudo tail -f /var/log/cron
The task will now run automatically at the specified schedule.
