What is a cron job (crontab)?
On Linux (or UNIX) servers, the Cron service is a daemon (a background program) that automatically runs commands or scripts at specific dates and times. The table that lists these tasks is called the Crontab.
It is essential in modern web development. For example, the Laravel PHP framework uses a single cron job (* * * * * cd /path-to-your-project && php artisan schedule:run) that runs every minute to handle deferred emails, database cleanup and automatic backups.
Understanding the syntax (the 5 stars)
A cron expression is made of 5 required fields separated by spaces. Here are the special characters to master:
| Symbol | Meaning | Example |
|---|---|---|
* (Asterisk) |
All values (every) | * in the "Month" field means "every month". |
, (Comma) |
Value separator (and) | 1,15 in "Day" runs on the 1st AND the 15th of the month. |
- (Hyphen) |
Range of values (from... to) | 1-5 in "Day of week" runs from Monday to Friday. |
/ (Slash) |
Step value (every X) | */5 in "Minute" runs every 5 minutes. |