Run tasks at specific times or intervals using cron or at.
Most common scheduler. Edit user crontab:
crontab -e
Edit root crontab:
sudo crontab -e
List your crons:
crontab -l
minute hour day month day-of-week command 0 2 * * * /path/to/backup.sh
Fields:
- minute — 0-59
- hour — 0-23
- day — 1-31
- month — 1-12
- day-of-week — 0-6 (0=Sunday)
Special values:
- * — any value
- */5 — every 5 units
- 1-5 — range
- 1,3,5 — specific values
Examples:
0 2 * * * # 2 AM daily */30 * * * * # every 30 minutes 0 0 * * 0 # midnight Sunday (weekly) 0 0 1 * * # 1st of month (monthly) 0 0 1 1 * # 1 Jan (yearly) @reboot # on boot
Allow/deny users in:
sudo nano /etc/cron.allow # whitelist sudo nano /etc/cron.deny # blacklist
System cron jobs in:
ls /etc/cron.d/ cat /etc/crontab
List running cron processes:
ps aux | grep cron
View cron logs:
journalctl -u cron tail -f /var/log/syslog | grep CRON
Run once at a specific time:
at 3pm tomorrow at> /path/to/command at> [Ctrl+D]
List scheduled jobs:
atq
Remove job:
atrm jobid
Modern approach using systemd-run:
systemd-run --on-calendar="daily" /path/to/command
Or create a timer unit for complex scheduling.
0 2 * * * /backup.sh >> /var/log/backup.log 2>&1PATH if needed