What Is Cron?
Cron is a time-based job scheduler found in Unix and Unix-like operating systems including Linux, macOS, and FreeBSD. The word cron comes from the Greek word chronos, meaning time. The cron daemon runs continuously in the background and executes scheduled commands or scripts at specified intervals. System administrators and developers rely on cron to automate repetitive tasks such as running backups, clearing temporary files, sending scheduled emails, generating reports, rotating log files, and synchronizing data between systems.
Cron was originally written by Ken Thompson for Version 7 Unix in the late 1970s and has since evolved through several implementations. The most widely used version today is Vixie cron, written by Paul Vixie in 1987, which forms the basis of the cron implementations shipped with most Linux distributions. Despite being nearly five decades old, cron remains one of the most important and widely used utilities in the Unix ecosystem. Every Linux server, from a Raspberry Pi to a cloud instance running critical infrastructure, typically has the cron daemon running.
The power of cron lies in its simplicity. You define when a job should run using a compact five-field expression, and cron takes care of executing it at the right time. There are no complex configuration files, no graphical interfaces to navigate, and no dependencies to install. You write a cron expression, pair it with a command, and the system handles the rest. This simplicity has ensured cron's longevity and made it a foundational tool that every developer and system administrator should understand.
Cron Expression Syntax
A standard cron expression consists of five fields separated by spaces. Each field represents a unit of time and defines when the scheduled task should execute. The five fields, from left to right, are:
- Minute (0-59): The minute of the hour when the job runs.
- Hour (0-23): The hour of the day in 24-hour format. 0 is midnight, 12 is noon, 23 is 11 PM.
- Day of Month (1-31): The day of the month. Note that not all months have 31 days; cron will skip invalid dates.
- Month (1-12): The month of the year. January is 1, December is 12. Some cron implementations also accept three-letter abbreviations like JAN, FEB, MAR.
- Day of Week (0-6): The day of the week. Sunday is 0, Saturday is 6. Like months, some implementations accept abbreviations like SUN, MON, TUE. In many implementations, 7 is also accepted as Sunday.
A complete cron entry in a crontab file consists of the five-field time specification followed by the command to execute. For example, 30 2 * * * /usr/local/bin/backup.sh runs the backup script at 2:30 AM every day. The time specification and the command are separated by one or more spaces or tabs.
Special Characters Explained
Cron expressions use several special characters to create flexible schedules. Understanding these characters is essential to writing effective cron expressions.
Asterisk (*) - Any Value
The asterisk matches all possible values for a field. In the minute field, * means every minute (0 through 59). In the hour field, it means every hour. The expression * * * * * runs every single minute of every hour of every day. This is the most permissive wildcard and is the default starting point for building a cron expression.
Comma (,) - Value List
The comma separates individual values within a field. For example, 0,15,30,45 * * * * runs at minutes 0, 15, 30, and 45 of every hour. You can combine as many values as needed: 1,2,3,4,5 in the day-of-week field runs the job Monday through Friday. The values do not need to be in order, though keeping them sorted improves readability.
Hyphen (-) - Range
The hyphen defines a contiguous range of values. Instead of writing 1,2,3,4,5 you can write 1-5 in the day-of-week field to represent Monday through Friday. Ranges are inclusive on both ends. In the hour field, 9-17 means every hour from 9 AM through 5 PM. Ranges can be combined with commas: 1-5,15,30 in the minute field matches minutes 1, 2, 3, 4, 5, 15, and 30.
Slash (/) - Step Value
The slash defines step values (intervals). The syntax is start/step where start is the beginning value and step is the increment. For example, */5 in the minute field means every 5 minutes starting from 0 (equivalent to 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55). You can also specify a starting point: 2/5 means minutes 2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57. Steps work with ranges too: 1-30/5 means minutes 1, 6, 11, 16, 21, 26.
Common Cron Schedules
Here are some of the most frequently used cron expressions that cover typical scheduling scenarios:
* * * * *- Every minute. Useful for monitoring scripts or heartbeat checks, but be cautious about resource usage.*/5 * * * *- Every 5 minutes. A popular choice for polling scripts and lightweight status checks.0 * * * *- Every hour, at minute 0. Good for hourly reports, cache clearing, or data synchronization.0 0 * * *- Once a day at midnight. The standard schedule for daily backups, log rotation, and cleanup tasks.0 0 * * 0- Once a week on Sunday at midnight. Common for weekly reports, full backups, and maintenance windows.0 0 1 * *- Once a month on the 1st at midnight. Used for monthly reports, billing tasks, and data archival.0 0 1 1 *- Once a year on January 1st at midnight. Certificate renewal reminders, annual cleanup jobs.0 9 * * 1-5- Every weekday at 9 AM. Perfect for business-hour notifications and daily standup reminders.0 9-17 * * 1-5- Every hour during business hours on weekdays. Good for periodic business-hour checks.*/15 * * * *- Every 15 minutes. A balanced frequency for monitoring and data synchronization.0 0,12 * * *- Twice a day at midnight and noon. Useful for semi-daily reports or data pulls.30 4 * * *- Once a day at 4:30 AM. Common for database backups during low-traffic hours.
Cron in Different Systems
While the five-field cron expression is the universal standard, different systems and platforms implement cron with slight variations and extensions. Understanding these differences is important if you work across multiple environments.
Standard Unix/Linux Cron
The traditional Unix cron (Vixie cron) uses the five-field format described above. Crontab files are edited using the crontab -e command, which opens the user's cron table in a text editor. Each line contains a time specification followed by a command. Lines starting with # are comments. The crontab also supports environment variable assignments (like PATH=/usr/local/bin:/usr/bin) at the top of the file. The system crontab (/etc/crontab) includes an additional sixth field between the time specification and the command that specifies which user account should run the job.
Extended Cron (6 or 7 Fields)
Some cron implementations add a seconds field as the first position, creating a six-field expression. Quartz Scheduler (commonly used in Java applications), Spring Framework's @Scheduled annotation, and AWS EventBridge all support a seconds field. Some implementations also add a seventh field for the year. When working with these extended formats, always check the documentation for your specific platform to understand exactly which fields are expected and in what order.
Predefined Schedules
Many cron implementations support shorthand strings that replace the five-field expression. These include: @yearly or @annually (equivalent to 0 0 1 1 *), @monthly (equivalent to 0 0 1 * *), @weekly (equivalent to 0 0 * * 0), @daily or @midnight (equivalent to 0 0 * * *), @hourly (equivalent to 0 * * * *), and @reboot which runs once when the cron daemon starts.
Cloud Platforms
Cloud providers have adopted cron-like syntax for their scheduling services. AWS CloudWatch Events and EventBridge use a modified cron syntax with six fields (including seconds or year) and support additional characters like ? (no specific value) and L (last day). Google Cloud Scheduler uses standard five-field cron syntax. Azure Functions Timer Triggers use NCRONTAB format which adds a seconds field. Kubernetes CronJobs use standard five-field syntax. GitHub Actions uses standard five-field cron for scheduled workflows. When migrating cron jobs to the cloud, always verify that your expression works correctly in the target platform's cron dialect.
Node.js and JavaScript
Libraries like node-cron, cron (npm package), and node-schedule bring cron functionality to JavaScript applications. Most use the standard five-field syntax, though node-cron supports an optional seconds field as the first position. These libraries are commonly used for scheduling background tasks in web servers, running periodic data processing, sending scheduled notifications, and managing queue workers. The croner library is a modern alternative that supports both five-field and six-field expressions with excellent TypeScript support.
Cron Best Practices
Writing effective cron jobs goes beyond getting the expression syntax right. Here are some best practices that experienced system administrators follow:
- Log output: Always redirect stdout and stderr to a log file. A cron entry like
0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1captures all output for debugging. - Use absolute paths: Cron runs with a minimal environment. Always use full paths for commands and files to avoid "command not found" errors.
- Avoid overlapping runs: If a job takes longer than the interval between runs, you can end up with multiple instances running simultaneously. Use a lock file mechanism (like
flock) to prevent overlap. - Stagger job times: Do not schedule all your cron jobs at the same time (like midnight on the hour). Stagger them by a few minutes to spread the load on your server.
- Test expressions before deploying: Use a tool like this cron expression generator to verify your expression produces the schedule you intend before putting it into production.
- Set a MAILTO variable: Configure
MAILTO=your@email.comin your crontab so that cron emails you any output or errors from your jobs. - Keep jobs idempotent: Design your cron jobs so that running them multiple times produces the same result. This makes your system resilient to accidental double-runs or retries after failures.
Troubleshooting Cron Jobs
When a cron job does not run as expected, several common issues might be the cause. First, check that the cron daemon is running with systemctl status cron or service cron status. Verify your crontab is saved correctly with crontab -l. Check the system log (/var/log/syslog or /var/log/cron) for entries showing when cron attempted to run your job. Ensure the script has execute permissions (chmod +x script.sh) and uses the correct shebang line (#!/bin/bash). Remember that cron runs with a minimal PATH; if your script depends on specific commands, set the PATH explicitly or use absolute paths throughout.
A common pitfall is editing the crontab file directly in /var/spool/cron/ instead of using crontab -e. The crontab -e command validates syntax before saving, while direct editing does not. Another frequent issue is timezone confusion. Cron jobs run in the system's timezone by default. If your server is set to UTC but you expect jobs to run in your local timezone, you will see unexpected timing. Some cron implementations allow setting CRON_TZ=America/New_York in the crontab to override the timezone for specific jobs.
About This Tool
This cron expression generator runs entirely in your browser. No data is sent to any server. Use the visual editor to build expressions by selecting the mode (every, specific, range, or step) for each of the five cron fields. The tool generates the corresponding cron expression in real time, provides a human-readable description of the schedule, and calculates the next five scheduled run times from the current date and time.
You can also type or paste a cron expression directly into the manual input field and click Parse to populate the visual editor. This is useful for understanding an existing cron expression that you found in a crontab file or configuration. The tool supports the standard five-field cron format used by Unix/Linux cron, Kubernetes CronJobs, GitHub Actions, and most other cron implementations. It does not support seconds fields, year fields, or platform-specific extensions like the ? character used by AWS.
Related Tools
- Unix Timestamp Converter -- Convert between Unix timestamps and human-readable dates.
- Regex Tester -- Test regular expressions with real-time matching and highlighting.
- JSON Formatter -- Format, validate, and minify JSON data.