What is a Cron Job?
A cron job is a scheduled task that runs automatically at specific times on Linux and Unix systems. Want to back up your database every night at 2 AM? Or clear temp files every Sunday? That's what cron does. You write the schedule, cron handles the rest.
Fun fact: "Cron" comes from the Greek word "chronos" meaning time. It's been around since the 1970s.
How Cron Works
flowchart LR
A[Crontab File] --> B[Cron Daemon]
B --> C{Time Match?}
C -->|Yes| D[Run Command]
C -->|No| E[Wait]
E --> C
D --> F[Log Output]
The cron daemon runs in the background, checking every minute if any scheduled tasks need to run.
Cron Expression Format
A cron expression has 5 fields separated by spaces. Each field tells cron when to run:
0-59
0-23
1-31
1-12
0-6
💡 Tip: An asterisk (*) means "every" - so * * * * * runs every minute.
Special Characters
* Asterisk
Matches every value. * * * * * = every minute of every hour of every day.
, Comma
List multiple values. 0 9,17 * * * = at 9 AM and 5 PM.
- Hyphen
Range of values. 0 9-17 * * * = every hour from 9 AM to 5 PM.
/ Slash
Step values. */15 * * * * = every 15 minutes.
Generating a Cron Expression
You don't have to write cron syntax by hand. The fastest way to get a correct schedule is to use a cron expression generator: you describe when the job should run, and the generator produces a valid crontab line for you. Here is how to generate a cron expression:
1. Pick the schedule
Choose the minute, hour, day, month, and weekday for your job. For example, "every weekday at 9 AM" or "the 1st of every month at midnight".
2. Let the generator build the expression
A cron generator maps your choices to the five fields automatically. "Every weekday at 9 AM" becomes 0 9 * * 1-5, and "the 1st of every month at midnight" becomes 0 0 1 * *.
3. Add your command
Append the command to the generated expression to create a full crontab entry. 0 9 * * 1-5 becomes 0 9 * * 1-5 /path/to/report.sh, then add it with crontab -e.
The same approach works for Linux crontab, Kubernetes CronJobs, and GitHub Actions, since they all use the standard 5-field format.
Generate Your Cron Expression
Skip the syntax. Use our free cron expression generator to build, generate, and validate cron expressions in seconds.
Open the Cron Expression Generator →Common Examples
Every day at midnight. Good for daily backups or cleanup tasks.
Every weekday at 9 AM. Send daily reports, skip weekends.
Every 10 minutes. Health checks or monitoring.
Every Sunday at 2 AM. Weekly maintenance window.
First day of every month at midnight. Monthly reports or billing.
Managing Cron Jobs
Use the crontab command to manage your scheduled tasks:
crontab -l
# Edit your cron jobs
crontab -e
# Remove all your cron jobs (careful!)
crontab -r
⚠️ Watch out: Cron uses the system timezone. If your server is in UTC but you want 9 AM New York time, you'll need to convert. Use an epoch timestamp converter to see how times translate between UTC and your local timezone.
Crontab File Format
flowchart TB
subgraph crontab[Crontab Entry]
A["* * * * *"] --> B["/path/to/script.sh"]
end
A --> C[Schedule]
B --> D[Command to Run]
C --> E["When to run:
minute, hour, day, month, weekday"]
D --> F["What to run:
script, command, or program"]
Where Cron is Used
- Database Backups: Run pg_dump or mysqldump every night.
- Log Rotation: Clean up old log files to save disk space.
- Email Reports: Send daily or weekly summary emails.
- Data Sync: Pull data from APIs or sync with external services.
- Health Checks: Monitor services and alert if something's down.
Beyond Linux Cron
The cron syntax is used everywhere, not just Linux:
- GitHub Actions - Schedule workflows with cron syntax
- AWS CloudWatch Events - Trigger Lambda functions on schedule
- Kubernetes CronJobs - Run containerized tasks on schedule