What cron and crontab are
Cron is the scheduler built into Linux and other Unix systems. A background service called the cron daemon wakes up every minute, checks its list of jobs and runs any that are due. The list is called a crontab (cron table). Each line holds a schedule, written as a cron expression, followed by the command to run. People use it for backups, log cleanup, reports, renewing certificates and anything else that should repeat without anyone remembering to do it.
The five fields
A standard Unix cron expression has five fields separated by spaces. Read it left to right: minute, hour, day of month, month, day of week.
| Field | Allowed values | Names |
|---|---|---|
| Minute | 0-59 | none |
| Hour | 0-23 | none |
| Day of month | 1-31 | none |
| Month | 1-12 | JAN-DEC |
| Day of week | 0-7 (0 and 7 are Sunday) | SUN-SAT |
Special characters
* means every value in the field. A comma makes a list, so 1,15 is the 1st and 15th. A hyphen makes a range, so 9-17 is 9 to 17 inclusive. A slash sets a step: */5 is every 5th value, and 10-30/10 is 10, 20 and 30. You can combine them, for example 0,30 9-17 * * 1-5.
Common examples
| Expression | When it runs |
|---|---|
*/5 * * * * | Every 5 minutes |
0 * * * * | At the start of every hour |
30 2 * * * | Every day at 02:30 |
0 9 * * 1-5 | At 09:00, Monday through Friday |
0 0 1 * * | At 00:00 on day 1 of every month |
0 0 * * 0 | At 00:00 every Sunday |
crontab -e and crontab -l
Each user has their own crontab. Run crontab -e to open yours in an editor and add a line, and crontab -l to list what is there. Save the file and cron picks it up on its own, with no restart. Put the schedule first, then the command, and use full paths, because cron starts jobs with a very small environment and a short PATH.
30 2 * * * /usr/bin/php /var/www/app/cleanup.php
Output redirect and logging
Cron does not show a job's output anywhere you will see it. By default it tries to email the output to the job's owner, which usually goes nowhere on a server. Send it to a log file instead:
*/5 * * * * /path/to/command >> /var/log/job.log 2>&1
>> appends normal output to the file and 2>&1 sends error messages to the same place. When a job seems not to run, this log is the first thing to read.
The time zone gotcha
Cron uses the clock and time zone of the server, not your laptop or the time shown on this page. Many servers run on UTC. India Standard Time (IST) is UTC+5:30, so a job meant for 09:00 IST needs 30 3 * * * on a UTC server. Check the server with date or timedatectl, then either change the server's time zone, set a TZ variable on the crontab (some cron versions support it) or convert the hour yourself. The run times in the tool above use your browser's local time.
The day-of-month and day-of-week rule
This is the most surprising rule in cron. If both the day-of-month and the day-of-week fields are restricted, meaning neither is *, the job runs when either one matches, not both. So 0 0 13 * 5 runs on every 13th and also on every Friday, not only on Friday the 13th. If one of the two is *, only the other one applies. This is how standard Vixie cron behaves, and the tool follows it.
5 fields vs 6 fields (Quartz and Spring)
Unix cron has five fields and its smallest step is one minute. Some other schedulers, such as Quartz in Java and Spring's @Scheduled, use six or seven fields. The extra field is seconds at the start, and Quartz can add a year at the end. Those tools also use characters such as ?, L and W. A Quartz expression pasted into a Linux crontab will not work. This generator makes standard 5-field Unix cron only, and it will tell you if you paste in six fields.
Using cron on RapidServer
A RapidServer VPS (from ₹581/mo plus 18% GST) gives you full root on Linux, so you can use crontab -e directly. New to Linux? Read our Linux kya hai guide (in Hindi). On our cPanel web hosting, the panel includes a Cron Jobs tool where you paste the same five-field schedule. Find more free tools on the calculators page.
A Linux VPS with full root, daily backups kept for 7 days and a choice of Mumbai or Delhi NCR.
See VPS hostingFrequently asked questions
How do I run a cron job every 5 minutes?+
*/5 * * * *. The slash in the minute field means every 5th minute: 0, 5, 10 and so on up to 55.Does cron support seconds?+
sleep inside the job, a systemd timer or a process manager. Tools such as Quartz do have a seconds field.What do 0 and 7 mean in the day-of-week field?+
0 0 * * 0 and 0 0 * * 7 are the same.Why is my cron job not running?+
PATH, a script without execute permission, a percent sign in the command (cron treats an unescaped % as a newline), the wrong time zone, or a syntax mistake in the crontab. Redirect output to a log file and read it.How do I run a job at every reboot?+
@reboot in place of the five fields, for example @reboot /path/to/command. It runs once when the cron daemon starts.What is the difference between crontab -e and /etc/crontab?+
crontab -e edits your own user crontab. The system file /etc/crontab has an extra column after the five fields that names the user to run the job as.