ESC
Developer

Cron Job Syntax: Complete Guide to Scheduling Tasks in Linux

Master cron job syntax with clear examples. Learn the five time fields, special characters, common schedules, and how to test your expressions.

2026-06-29 8 min read Developer
Cron Job Syntax Guide

What Is a Cron Job?

Cron is a time-based job scheduler built into Unix-like operating systems. A cron job is a command or script that runs automatically on a defined schedule. Cron reads configuration files called crontabs (cron tables) and executes the listed commands at the specified times.

Common uses: database backups, sending scheduled emails, clearing cache, rotating logs, running data sync scripts, and any recurring task you don't want to trigger manually.

Cron Syntax: The Five Fields

Every cron expression has exactly five time fields followed by the command to run:

┌───────────── minute (0–59)
│ ┌───────────── hour (0–23)
│ │ ┌───────────── day of month (1–31)
│ │ │ ┌───────────── month (1–12)
│ │ │ │ ┌───────────── day of week (0–6, Sunday=0)
│ │ │ │ │
* * * * *  command to execute

Special Characters

CharacterMeaningExample
*Every value (wildcard)* * * * * — every minute
,List of values0 9,17 * * * — at 9:00 and 17:00
-Range of values0 9-17 * * * — every hour 9:00–17:00
/Step values*/15 * * * * — every 15 minutes
LLast (some systems)0 0 L * * — last day of month

20 Practical Cron Examples

ExpressionWhen it runs
* * * * *Every minute
*/5 * * * *Every 5 minutes
*/15 * * * *Every 15 minutes
0 * * * *Every hour (at :00)
0 */2 * * *Every 2 hours
0 0 * * *Daily at midnight
0 6 * * *Daily at 6:00 AM
0 9,17 * * *Twice daily — 9 AM and 5 PM
0 9-17 * * 1-5Every hour, 9–17, weekdays only
0 0 * * 1Every Monday at midnight
0 0 1 * *1st of every month at midnight
0 0 1 1 *January 1st at midnight (yearly)
30 4 * * 0Every Sunday at 4:30 AM
0 0 * * 1-5Midnight, Monday to Friday
0 8 1-7 * 1First Monday of every month at 8 AM
*/30 8-18 * * 1-5Every 30 min, 8–18, weekdays
0 2 * * 6,0Saturdays and Sundays at 2 AM
59 23 * * 5Every Friday at 23:59
0 12 15 * *15th of every month at noon
5 4 * * sunSunday at 04:05 (using name)

Predefined Schedule Strings

Most modern cron implementations support shorthand strings instead of the five-field syntax:

@reboot    Run once at startup
@yearly    Run once a year   (= 0 0 1 1 *)
@annually  Same as @yearly
@monthly   Run once a month  (= 0 0 1 * *)
@weekly    Run once a week   (= 0 0 * * 0)
@daily     Run once a day    (= 0 0 * * *)
@midnight  Same as @daily
@hourly    Run once an hour  (= 0 * * * *)

Working with Crontab

# Open your user crontab for editing
crontab -e

# List your current crontab
crontab -l

# Remove your crontab (careful — no confirmation!)
crontab -r

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

Output and Logging

By default, cron sends output as email to the local user. In practice, redirect output to a log file:

# Redirect stdout and stderr to a log file
*/5 * * * * /path/to/script.sh >> /var/log/myjob.log 2>&1

# Suppress all output (silent cron job)
*/5 * * * * /path/to/script.sh > /dev/null 2>&1

# Append to log with timestamps (using bash)
*/5 * * * * echo "$(date): job ran" >> /var/log/myjob.log
Common mistake: Cron runs with a minimal environment — PATH only includes /usr/bin:/bin. Always use full paths for commands and scripts, or set PATH at the top of your crontab.

Timezone in Cron

Cron uses the system timezone by default. To use a different timezone, set the CRON_TZ variable at the top of your crontab:

CRON_TZ=Europe/Istanbul
0 9 * * * /path/to/morning-report.sh

On systems using systemd timers or newer cron implementations (Vixie cron, fcron), check /etc/crontab and /etc/cron.d/ for system-wide jobs.

Frequently Asked Questions

Why isn't my cron job running?

The most common causes: (1) wrong path — cron's PATH is minimal, always use full paths; (2) permissions — the script must be executable (chmod +x script.sh); (3) syntax error in the expression — test with an online validator first; (4) cron daemon not running (systemctl status cron); (5) output is going to mail and failing silently.

Can I run a cron job every 10 seconds?

No — the minimum interval for standard cron is 1 minute. For sub-minute scheduling, use sleep tricks (* * * * * sleep 30; command), systemd timers with OnCalendar=*:*:0/30, or a dedicated tool like fcron.

What is the difference between crontab and /etc/cron.d?

User crontabs (crontab -e) are per-user and have no username field. System crontabs in /etc/cron.d/ are run as root by default and include an extra username field between the time expression and the command: */5 * * * * www-data /usr/bin/php /var/www/cron.php.

How do I test a cron expression without waiting?

Use an online cron expression tester to see the next N run times, or temporarily set the job to run every minute and watch the logs. You can also test the command directly in your shell first, then add it to cron once confirmed working.

Cron Syntax Cheat Sheet

All cron patterns and examples on one page — search, copy, use instantly.

Open Cheat Sheet

Build Cron Expressions Visually

Generate any cron schedule without memorizing syntax — pick your interval and get the expression instantly.

Also on MoreOnlineTools