A cron job is a scheduled task or automated job that runs at specified intervals on Unix-like operating systems. The name “cron” comes from the Greek word “chronos,” meaning time, and it is a time-based job scheduler in Unix and Unix-like operating systems.
Cron jobs are managed by the cron daemon, which is a background process that executes scheduled tasks at the predetermined times or intervals. These tasks can include running scripts, executing programs, or performing system maintenance activities.
Here’s the basic structure of a cron job:
* * * * * command-to-be-executed | | | | | | | | | +----- Day of the week (0 - 6) (Sunday = 0 or 7) | | | +------- Month (1 - 12) | | +--------- Day of the month (1 - 31) | +----------- Hour (0 - 23) +------------- Minute (0 - 59)
Each asterisk (*) represents a wildcard, meaning “every” for the respective time unit. For example, if you have
* * * * * as the schedule, it means the command will run every minute. You can replace the asterisks with specific values to set a more precise schedule.
For example, a cron job to run a script every day at 2:30 PM would look like:
30 14 * * * /path/to/your/script.sh
To create or edit a cron job, you can use the
crontab command. For example, to edit your user’s cron jobs, you can run:
This opens your user’s crontab file in an editor where you can add or edit your scheduled tasks.
To see a list of active, scheduled tasks. You can run:
Cron jobs are an essential tool for automating routine tasks on Unix-based systems, making them a fundamental part of system administration and automation.