How to Schedule Tasks with Cron: A Beginner's Guide
Run commands on a schedule in Linux with cron: the five time fields, ready examples, how to edit your crontab, where the output goes, and why a job fails.
3 min readBy Soumya
Reviewed by the AmazingRDP technical team

Scheduled jobs need a machine that is always on. A Linux VPS gives you root access. See Linux VPS from $6.99
Cron is the Linux service that runs commands at set times: a backup every night, a clean-up every Sunday, a check every five minutes. Each user has a list of jobs, the crontab. One line is one job.
Edit your crontab
crontab -e
crontab -l
The first opens your list in an editor (the first time, it asks which; nano is the easy one). The second prints it. Saving the file is enough; there is nothing to restart. To edit root's list, use sudo crontab -e.
Take care with crontab -r: it deletes the whole list without asking, and r sits next to e on the keyboard.
The five time fields
* * * * * command
| | | | |
| | | | +-- day of week (0 to 7; 0 and 7 are Sunday)
| | | +---- month (1 to 12)
| | +------ day of month (1 to 31)
| +-------- hour (0 to 23)
+---------- minute (0 to 59)
| Sign | Meaning | Example |
|---|---|---|
* | Every value | * in the hour field: every hour |
, | A list | 1,15: on the 1st and the 15th |
- | A range | 1-5: Monday to Friday |
/ | A step | */10: every tenth |
Examples to copy
30 2 * * * /home/alex/backup.sh
*/10 * * * * /home/alex/check.sh
0 9 * * 1-5 /home/alex/report.sh
0 0 1 * * /home/alex/monthly.sh
15 3 * * 0 /usr/bin/apt-get -y autoremove
@reboot /home/alex/start-app.sh
In order: every day at 02:30; every ten minutes; at 09:00 on weekdays; at midnight on the first of each month; Sundays at 03:15; once at every start of the machine. Other shortcuts are @hourly, @daily, @weekly and @monthly.
Where does the output go?
Nowhere you will see, unless you say so. Send it to a file:
30 2 * * * /home/alex/backup.sh >> /home/alex/backup.log 2>&1
>> appends to the file and 2>&1 includes error messages. This one habit makes most cron problems easy to solve. Watch the file with tail.
Why a job works by hand and not in cron
| Cause | Fix |
|---|---|
| Cron's PATH is very short | Write full paths: /usr/bin/python3, not python3. Find them with which python3 |
| The script is not executable | chmod +x script.sh, or call it as /bin/bash /path/script.sh. See how to run a shell script |
| It relies on your login settings | Cron does not read .bashrc. Set needed variables inside the script |
| It uses relative paths | Cron starts in your home folder. Use full paths, or cd first |
A % in the command | In a crontab % means a new line. Write \%, as in date +\%F |
| The time is off by hours | Cron uses the system's time zone: check with timedatectl |
Did it run?
grep CRON /var/log/syslog | tail -n 20
journalctl -u cron -n 20
On the RHEL family the service is called crond and the log is /var/log/cron. These show that a job was started, not whether it succeeded; for that you need its own log file.
System-wide jobs
Besides the per-user lists there are folders for the whole system: scripts placed in /etc/cron.daily, /etc/cron.weekly and so on run at those intervals, and files in /etc/cron.d use the crontab format with one extra field for the user name.
Good habits
- Do not start everything on the hour. Spread jobs across the minutes.
- Stop a job from overlapping itself if it can run longer than its interval:
flock -n /tmp/job.lock /path/job.sh. - Test the command first by hand, with the full paths, exactly as written in the crontab.
- Check a schedule on a site such as crontab.guru before trusting it.
Cron or systemd timers?
Current systems offer systemd timers as an alternative, with built-in logging and catch-up of missed runs. Cron remains simpler for a single line, and it is everywhere.
Scheduled jobs belong on a machine that never sleeps: see our Linux VPS plans.
Questions
How do I create a cron job?
Run crontab -e, add a line with five time fields and the command, and save.
What does * * * * * mean in cron?
Every minute. The five fields are minute, hour, day of month, month and day of week.
Why is my cron job not running?
Most often because cron has a short PATH. Use full paths for every command and file, and write the output to a log file.
How do I run a cron job every 5 minutes?
Use */5 * * * * followed by the command.