Member-only story
Mastering task automation on Linux using cron jobs is a great way to streamline repetitive tasks like backups, updates, and more. Here’s a guide to help you understand and use cron jobs effectively:
1. What is Cron?
Cron is a time-based job scheduler in Unix-like operating systems. It allows you to run commands or scripts at scheduled times or intervals. A cron job is defined by a cron expression, which specifies the minute, hour, day of the month, month, and day of the week.
2. Cron Syntax
Cron jobs are scheduled using a file called the crontab (cron table). The syntax of a cron job is as follows:
* * * * * /path/to/command
- - - - -
| | | | |
| | | | +---- Day of the week (0 - 7) (Sunday = 0 or 7)
| | | +------ Month (1 - 12)
| | +-------- Day of the month (1 - 31)
| +---------- Hour (0 - 23)
+------------ Minute (0 - 59)
Here’s a breakdown of the fields:
- Minute: (0–59)
- Hour: (0–23)
- Day of the month: (1–31)
- Month: (1–12)
- Day of the week: (0–7) (where both 0 and 7 represent Sunday)
3. Managing Cron Jobs
a. Listing Existing Cron Jobs
To list the current cron jobs for your user:
crontab -l