🐧 Linux / Shell Scripting
Intermediate
How does cron work and how do you edit crontabs?
Answer
cron is the Linux task scheduler that runs commands on a defined time schedule. Edit the user's crontab with crontab -e; list it with crontab -l. Each cron entry has five time fields followed by the command: * * * * * /path/to/command (minute, hour, day-of-month, month, day-of-week). Examples: 0 2 * * * /scripts/backup.sh (daily at 2 AM), */15 * * * * /scripts/check.sh (every 15 minutes), 0 9 * * 1 /scripts/weekly.sh (every Monday at 9 AM). System-wide crontabs live in /etc/cron.d/. Always use absolute paths in cron commands because the environment is minimal. Redirect output to avoid silent failures: command >> /var/log/cron.log 2>&1.