How to Schedule Tasks in Linux with cron
The cron daemon runs commands automatically on a schedule you define. You edit your jobs with crontab -e, and each job line says when to run and what to run: 0 2 * * * /home/user/backup.sh runs the backup at 2 AM every day. This guide decodes the schedule syntax.
Open your crontab
Each user has their own crontab. Open yours with crontab -e. The first time, you pick an editor; the default is fine.
The five time fields
Every job line starts with five fields: minute, hour, day of month, month, day of week. An asterisk means every value. So 0 2 * * * means minute 0, hour 2, every day, every month, every weekday.
Real schedule examples
Daily at 2 AM: 0 2 * * *. Every 15 minutes: */15 * * * *. Every weekday at 9 AM: 0 9 * * 1-5. Midnight on the first of the month: 0 0 1 * *.
A full backup job
Put the command after the schedule. This creates a tar archive every day at 2:30 AM and logs the result:
Note the \%: cron treats a plain % as a newline, so the date format needs the escape.
Check that it ran
Cron emails job output by default, which on most servers ends up nowhere. Log output yourself with >>, and list your jobs with crontab -l. To run a command at every reboot instead, add @reboot before the command.
The crontab reference page documents the full syntax and special strings.
Keep learning
Related guides: How to Reuse Commands with the bash history Feature · How to Compress and Extract Files with tar · Linux Environment Variables: How to Set and Use Them. Read all tutorials on the Learn Linux blog.