crontab (cron table) is a command-line utility for scheduling automated tasks in Linux. It allows users to execute scripts or commands at specified times or intervals, enabling task automation.
Key Commands:
– View Crontab: crontab -l
– Edit Crontab: crontab -e
– Remove Crontab: crontab -r
– Edit for a Specific User: crontab -u username -e
Syntax:
* * * * * command_to_execute
– – – – –
| | | | |
| | | | +— Day of the week (0 – 7)
| | | +—– Month (1 – 12)
| | +——- Day of the month (1 – 31)
| +——— Hour (0 – 23)
+———– Minute (0 – 59)
Examples:
1. Run a script daily at 5 AM:
0 5 * * * /path/to/script.sh
2. Delete logs every Sunday at midnight:
0 0 * * 0 rm -rf /var/log/*.log
3. Check a website every hour:
0 * * * * curl http://example.com
Crontab simplifies repetitive task management, enhancing productivity