What Is a Cron Expression?
A cron expression is a string of five (or six) fields separated by spaces that defines a recurring schedule for automated tasks. It is used by the Unix/Linux cron daemon to trigger scripts, commands or programs at specified times. The five standard fields represent β in order β minute, hour, day of month, month and day of week.
For example, 0 9 * * 1-5 means "at 09:00 on every weekday", and */15 * * * * means "every 15 minutes". Beyond Unix cron, the Quartz scheduler (used in Java) adds a sixth seconds field at the start.
Cron Syntax Cheat Sheet
| Expression | Description |
|---|---|
| * * * * * | Every minute |
| 0 * * * * | Every hour (on the hour) |
| 0 0 * * * | Every day at midnight |
| 0 9 * * 1-5 | Weekdays at 9:00 AM |
| 0 0 * * 0 | Every Sunday at midnight |
| 0 0 1 * * | 1st of every month at midnight |
| 0 0 1 1 * | Every year on January 1st |
| */5 * * * * | Every 5 minutes |
| 0 9,18 * * * | At 9 AM and 6 PM daily |
| 0 0 15 * * | 15th of every month at midnight |
Special Characters Explained
- Asterisk (*) β matches all values in the field (every minute, every hour, etc.)
- Comma (,) β separates a list of values:
1,3,5means 1st, 3rd and 5th - Hyphen (-) β defines a range:
9-17means every hour from 9 to 17 - Slash (/) β defines a step:
*/10means every 10 units;5/10means 5, 15, 25β¦ - L β stands for "last": in day-of-month it means the last day of the month
How to Add a Cron Job on Linux
Open the crontab editor with crontab -e, then add your expression followed by the command to execute. For example: 0 2 * * * /usr/bin/python3 /home/user/backup.py runs a backup script every day at 2 AM. Save and exit β cron picks up the change immediately. Use crontab -l to list all current jobs.