Cron Expressions Explained: Syntax, Examples, and Common Patterns

Β· 10 min read

Cron Syntax: The Five Fields

A cron expression has five fields separated by spaces. Each field defines when the job runs:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ minute (0-59)
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ hour (0-23)
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ day of month (1-31)
β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ month (1-12 or JAN-DEC)
β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ day of week (0-7, 0 and 7 = Sunday, or SUN-SAT)
β”‚ β”‚ β”‚ β”‚ β”‚
* * * * * command
FieldRangeSpecial Characters
Minute0-59* , - /
Hour0-23* , - /
Day of Month1-31* , - / L W
Month1-12* , - /
Day of Week0-7* , - / L #

Special Characters

CharacterMeaningExample
*Every value* * * * * = every minute
,List of values1,15 * * * * = minute 1 and 15
-Range0 9-17 * * * = every hour 9am-5pm
/Step/interval*/5 * * * * = every 5 minutes
LLast (day of month/week)0 0 L * * = last day of month
WNearest weekday0 0 15W * * = nearest weekday to 15th
#Nth weekday0 0 * * 5#3 = 3rd Friday

Note: L, W, and # are extensions not available in all cron implementations. Standard Unix cron supports *, ,, -, and / only.

Common Patterns

ExpressionDescription
* * * * *Every minute
*/5 * * * *Every 5 minutes
0 * * * *Every hour (at minute 0)
0 */2 * * *Every 2 hours
0 0 * * *Daily at midnight
0 9 * * *Daily at 9:00 AM
0 9 * * 1-5Weekdays at 9:00 AM
0 0 * * 0Weekly on Sunday at midnight
0 0 1 * *First day of every month
0 0 1 1 *January 1st at midnight (yearly)
30 4 * * 1Monday at 4:30 AM
0 0 * * 6,0Weekends at midnight
0 8-17 * * 1-5Every hour during business hours
0 0 1,15 * *1st and 15th of each month
*/10 * * * *Every 10 minutes

Build and test expressions with our Cron Expression Generator or parse existing ones with Cron Expression Parser.

Managing Crontab

# Edit your crontab
crontab -e

# List current crontab entries
crontab -l

# Remove all crontab entries (careful!)
crontab -r

# Edit another user's crontab (root only)
crontab -u username -e

# Example crontab file
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
[email protected]

# Backup database daily at 2 AM
0 2 * * * /home/user/scripts/backup.sh >> /var/log/backup.log 2>&1

# Clean temp files every Sunday at 3 AM
0 3 * * 0 find /tmp -mtime +7 -delete

# Health check every 5 minutes
*/5 * * * * curl -s https://example.com/health > /dev/null

Crontab Tips

Common Pitfalls

  1. Environment variables β€” Cron runs with a minimal environment. Your script may work in terminal but fail in cron because PATH, HOME, or other variables are different. Always use full paths or set variables explicitly.
  2. Timezone confusion β€” Cron uses the system timezone by default. Set CRON_TZ in your crontab if needed.
  3. Day of month AND day of week β€” When both are set (not *), cron runs when EITHER matches, not both. 0 0 1 * 5 runs on the 1st AND every Friday, not "the 1st if it's a Friday."
  4. Percent signs β€” In crontab, % is a newline character. Escape with \% or put the command in a script.
  5. No seconds field β€” Standard cron minimum is 1 minute. For sub-minute scheduling, use a wrapper script with sleep.

Alternatives to Cron

ToolAdvantageUse Case
systemd timersBetter logging, dependencies, randomized delayModern Linux systems
atOne-time scheduled executionRun once at a specific time
anacronRuns missed jobs after downtimeLaptops, machines that sleep
node-cronIn-process scheduling for Node.jsApplication-level scheduling
Celery BeatDistributed task schedulingPython/Django applications
GitHub ActionsCloud-based, cron syntax supportedCI/CD pipelines

Frequently Asked Questions

What does * mean in cron?

The asterisk (*) means "every" β€” it matches all possible values for that field. * in the minute field means every minute, * in the hour field means every hour, and so on.

How do I run a cron job every 5 minutes?

Use */5 * * * * β€” the */5 in the minute field means "every 5th minute" (0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55).

What is the difference between cron and crontab?

Cron is the daemon (background service) that executes scheduled tasks. Crontab (cron table) is the configuration file that lists the schedule entries. You edit the crontab to tell cron what to run and when.

Can cron run every second?

No. Standard cron's minimum interval is 1 minute. For sub-minute scheduling, use a loop with sleep in a script, systemd timers with OnUnitActiveSec, or specialized tools like fcron.

What timezone does cron use?

By default, cron uses the system timezone. You can override this by setting CRON_TZ at the top of your crontab file, e.g., CRON_TZ=America/New_York.

Related Tools

Cron Generator Cron Parser Epoch Converter