crontab Command
Intermediate Logging & Monitoring man(1)Schedule recurring tasks with cron
👁 10 views
📅 Updated: Mar 15, 2026
SYNTAX
crontab [OPTION]... [FILE]
What Does crontab Do?
crontab schedules recurring tasks (cron jobs) to run automatically at specified times. Cron is the standard Linux task scheduler, used for backups, log rotation, reports, maintenance, and any periodic task.
Each user has their own crontab. The cron format specifies minute (0-59), hour (0-23), day of month (1-31), month (1-12), and day of week (0-7, where 0 and 7 are Sunday).
crontab provides a reliable, simple way to automate tasks. System-wide cron jobs go in /etc/crontab or /etc/cron.d/. Per-user jobs are managed with the crontab command.
Each user has their own crontab. The cron format specifies minute (0-59), hour (0-23), day of month (1-31), month (1-12), and day of week (0-7, where 0 and 7 are Sunday).
crontab provides a reliable, simple way to automate tasks. System-wide cron jobs go in /etc/crontab or /etc/cron.d/. Per-user jobs are managed with the crontab command.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -e | Edit your crontab | crontab -e |
| -l | List your crontab | crontab -l |
| -r | Remove your crontab | crontab -r |
| -u USER | Edit another user crontab (root only) | sudo crontab -u www-data -e |
Practical Examples
#1 Edit crontab
Opens crontab editor to add/modify scheduled tasks.
$ crontab -e#2 List cron jobs
Shows all scheduled tasks for current user.
$ crontab -l
Output:
0 2 * * * /usr/local/bin/backup.sh\n*/5 * * * * /usr/local/bin/check_health.sh
#3 Every 5 minutes
Runs every 5 minutes.
$ */5 * * * * /path/to/script.sh#4 Daily at 2 AM
Runs at 2:00 AM every day.
$ 0 2 * * * /path/to/backup.sh#5 Weekly on Sunday
Runs at 3:00 AM every Sunday.
$ 0 3 * * 0 /path/to/weekly_report.sh#6 Monthly on 1st
Runs at midnight on the 1st of every month.
$ 0 0 1 * * /path/to/monthly_cleanup.sh#7 With logging
Runs daily at 2 AM and logs output.
$ 0 2 * * * /path/to/backup.sh >> /var/log/backup.log 2>&1#8 Set environment
Sets shell, path, and email notification in crontab.
$ SHELL=/bin/bash\nPATH=/usr/local/bin:/usr/bin:/bin\nMAILTO=admin@example.com\n0 2 * * * backup.shTips & Best Practices
Cron format: m h dom mon dow: minute hour day-of-month month day-of-week. * means every. */5 means every 5. 1,15 means 1st and 15th.
PATH is minimal: Cron uses minimal PATH. Always use full paths in cron jobs: /usr/local/bin/python3 instead of python3.
Redirect output: Cron sends output as email. Redirect to log: >> /var/log/cron.log 2>&1. Or discard: > /dev/null 2>&1.
Frequently Asked Questions
How do I schedule a recurring task?
crontab -e opens the editor. Add a line: MIN HOUR DOM MON DOW command. Example: 0 2 * * * /path/to/script.sh (daily at 2 AM).
How do I run a command every 5 minutes?
Add to crontab: */5 * * * * /path/to/command. The */5 in the minute field means every 5 minutes.
Why does my cron job not work?
Common issues: wrong PATH (use full paths), no execute permission (chmod +x), output not redirected. Check /var/log/syslog for cron errors.
Related Commands
More Logging & Monitoring Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →