Crontab Expression: Syntax, Fields, and Examples
A crontab expression defines when cron runs a command using five time fields: minute, hour, day of the month, month, and day of the week. For example, the following entry runs a script every day at 02:30:
30 2 * * * /usr/local/bin/backup.sh
The five-field schedule is followed by the command you want to execute. You can build and preview the schedule visually on cronhub.online before adding it to your crontab.
Crontab expression format
A standard user crontab entry has six parts:
MINUTE HOUR DAY_OF_MONTH MONTH DAY_OF_WEEK COMMAND
The first five fields form the crontab expression. The remaining text is the command cron executes.
| Position | Field | Allowed values |
|---|---|---|
| 1 | Minute | 0-59 |
| 2 | Hour | 0-23 |
| 3 | Day of month | 1-31 |
| 4 | Month | 1-12 or JAN-DEC |
| 5 | Day of week | 0-7 or SUN-SAT |
| 6 | Command | Executable, script, or shell command |
Both 0 and 7 commonly represent Sunday. Hours use the 24-hour clock, so 0 is midnight and 23 is 11 PM.
Consider this entry:
15 6 * * 1-5 /usr/local/bin/report.sh
Read it field by field:
- Minute: 15
- Hour: 6
- Day of month: every day
- Month: every month
- Day of week: Monday through Friday
- Command: run the report script
The result is 06:15 every weekday.
Crontab special characters
Crontab expressions use several operators to describe repeating or combined schedules.
| Character | Meaning | Example meaning |
|---|---|---|
* | Every allowed value | Every minute, hour, or day |
, | Multiple values | Hours 8 and 17 |
- | Inclusive range | Monday through Friday |
/ | Step interval | Every 10 minutes |
@ | Named shortcut | Run at reboot or daily |
Asterisk
An asterisk means every possible value for that field. This expression runs once per minute because all five fields allow every value:
* * * * * /usr/local/bin/worker.sh
An asterisk does not mean “run once.” It means the field places no restriction on the schedule.
Comma-separated lists
Use commas to select multiple values. This entry runs at 08:00 and 17:00 every day:
0 8,17 * * * /usr/local/bin/sync.sh
You can use lists in more than one field, but each added combination can produce another execution time.
Ranges
Use a hyphen for an inclusive range. This entry runs at 09:00 from Monday through Friday:
0 9 * * 1-5 /usr/local/bin/check-queue.sh
The range includes both endpoints, so days 1, 2, 3, 4, and 5 are selected.
Step values
A slash selects values at a fixed interval. This entry runs at minutes 0, 10, 20, 30, 40, and 50 of every hour:
*/10 * * * * /usr/local/bin/poll.sh
Steps operate within the field rather than measuring elapsed time from the previous run. If a job takes longer than the interval, cron may start another copy unless your command implements locking.
Common crontab expressions
Every minute
* * * * * /usr/local/bin/task.sh
Use this schedule carefully because failures, overlapping processes, and excessive output can accumulate quickly.
Every five minutes
*/5 * * * * /usr/local/bin/health-check.sh
This runs at minute 0, 5, 10, and so on through minute 55 of every hour.
Every hour
0 * * * * /usr/local/bin/hourly-task.sh
The minute field is fixed at 0, so the command runs at the beginning of each hour.
Every day at midnight
0 0 * * * /usr/local/bin/daily-cleanup.sh
Cron interprets midnight as hour 0.
Every day at 02:30
30 2 * * * /usr/local/bin/backup.sh
This is often called a nightly schedule, although the actual local time depends on the system’s configured timezone.
Every Monday at 09:00
0 9 * * 1 /usr/local/bin/monday-report.sh
You can usually write MON instead of 1, but numeric values are straightforward and avoid differences in accepted names.
On the first day of every month
0 4 1 * * /usr/local/bin/monthly-report.sh
This runs at 04:00 on day 1 of each month.
Every three months
0 0 1 */3 * /usr/local/bin/quarterly-task.sh
The month step begins at month 1, producing January, April, July, and October.
Day-of-month and day-of-week behavior
The day fields have an important rule. In common Unix cron implementations, if both day of the month and day of the week are restricted, the job runs when either field matches.
For example:
0 9 1 * 1 /usr/local/bin/report.sh
This normally runs at 09:00 on every Monday and on the first day of every month. It does not mean “the first Monday of the month.”
If you need the first Monday, run on the possible dates and let the command verify the weekday, or use a wrapper script:
0 9 1-7 * * /usr/local/bin/run-if-monday.sh
Your wrapper can exit without doing work when the date is not Monday. This approach is clearer and more portable than relying on nonstandard cron extensions.
Named crontab shortcuts
Many cron implementations support shortcuts in place of the five fields.
| Shortcut | Typical equivalent |
|---|---|
@yearly | Once per year |
@monthly | Once per month |
@weekly | Once per week |
@daily | Once per day |
@hourly | Once per hour |
@reboot | After the cron daemon starts |
For example:
@daily /usr/local/bin/daily-task.sh
The exact execution time of shortcuts such as @daily follows the cron implementation’s definition. Use explicit fields when the hour and minute matter.
An @reboot job runs when the cron daemon starts, which usually corresponds to boot but can also occur after the service is restarted:
@reboot /usr/local/bin/start-worker.sh
User crontabs versus system crontabs
A user crontab contains five schedule fields followed directly by the command:
0 3 * * * /usr/local/bin/backup.sh
System crontab files, including /etc/crontab, normally add a username between the schedule and command:
0 3 * * * root /usr/local/bin/backup.sh
Do not add the username when editing your personal crontab with crontab -e. If you copy an entry between locations, check which format the destination expects.
How to install a crontab expression
Open your current user’s crontab with:
crontab -e
Add the schedule and command on a new line:
0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
Save and close the editor. You can confirm the installed entries with:
crontab -l
To append an entry from the shell while preserving existing entries, use:
(crontab -l 2>/dev/null; printf '%s\n' '0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1') | crontab -
Review the resulting crontab afterward to make sure you did not create a duplicate.
Commands, paths, and environment variables
Cron usually runs with a smaller environment than your interactive shell. Use absolute paths for executables, scripts, configuration files, and output files.
Instead of relying on the current directory, change to it explicitly:
0 1 * * * cd /srv/example-app && /usr/bin/python3 /srv/example-app/manage.py cleanup >> /var/log/example-cleanup.log 2>&1
You can define environment variables at the top of a crontab:
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
[email protected]
These assignments are not cron expressions and do not have schedule fields. They apply to entries below them unless your implementation specifies otherwise.
In many traditional crontabs, an unescaped percent sign in the command is converted into a newline, and the remaining text is passed to standard input. Escape literal percent signs when using commands such as date:
0 1 * * * /usr/bin/date +\%F >> /var/log/dates.log 2>&1
Timezones and daylight saving time
Cron normally evaluates expressions in the daemon’s timezone. Confirm the server timezone rather than assuming it matches your workstation or users.
Some implementations support a CRON_TZ assignment:
CRON_TZ=UTC
0 6 * * * /usr/local/bin/report.sh
This feature is not universal, so check your installed cron implementation before depending on it. A portable alternative is to configure the host timezone intentionally or perform timezone-sensitive scheduling inside the application.
Daylight saving transitions can cause local times to be skipped or repeated. A job scheduled during a skipped hour may not run, while a repeated local time may produce implementation-specific behavior. Use UTC when you need predictable intervals across timezone changes.
Standard cron versus other expression formats
Traditional Unix crontab uses five time fields. Other schedulers may use six or seven fields, often adding seconds or a year.
Quartz-style schedulers also support operators such as ?, L, W, and #. These are not part of a portable five-field Unix crontab expression. Do not paste an expression from a cloud scheduler or application framework into Linux crontab without checking its field order and supported syntax.
Frequently Asked Questions
What is a crontab expression?
A crontab expression is a five-field schedule specifying the minute, hour, day of the month, month, and day of the week when cron should run. In a user crontab, the command appears immediately after those five fields.
Does a standard crontab expression include seconds?
No. Standard Unix crontab expressions begin with minutes and contain five time fields. Schedulers that accept seconds use a different format, so a six-field expression should not be copied into a standard Linux crontab without conversion.
How do I run a cron job every five minutes?
Use a step value in the minute field and allow every value in the other fields:
``bash
*/5 * * * * /usr/local/bin/task.sh
``
This runs at minutes 0, 5, 10, and every subsequent five-minute boundary.
Why does my cron command work manually but fail in crontab?
Cron may have a different working directory, a smaller PATH, missing environment variables, or different permissions. Use absolute paths, redirect standard output and errors to a log, and reproduce any required environment explicitly.
Is Sunday 0 or 7 in a crontab expression?
Common Unix cron implementations accept both 0 and 7 for Sunday. Using 0 is conventional, but you should verify the documentation when working with a non-Unix scheduler or application-specific cron parser.
Need the expression itself? Build and test any cron schedule in our free visual generator — with live upcoming-run previews in Unix and Quartz formats.
Related guides
References
- crontab manual page — documents Linux crontab fields, operators, environment variables, and day matching
- crontab command manual page — explains how to install, list, edit, and remove user crontabs
- Debian cron manual page — describes the cron daemon and how scheduled commands are executed