cron
is a daemon that runs in the background on a Linux or Unix-like system and executes tasks (also known as "cron jobs") at specified intervals. These tasks are usually defined in a configuration file called the crontab
(short for "cron tables").
cron
is typically used to schedule repetitive tasks, such as running backups, sending emails, or performing system maintenance. It allows you to automate tasks that need to be run on a regular basis.
To create a cron job, you need to specify when you want the task to be run and what command should be executed. This is done by editing the crontab
file and adding a line with the following format:
minute hour day_of_month month day_of_week command
For example, to run a task every day at midnight, you could use the following line in the crontab
file:
0 0 * * * command_to_execute
Each field in the crontab
line represents a time unit (minute, hour, day of the month, month, and day of the week) and can be specified as a single value (e.g., 0
for midnight), a range of values (e.g., 0-59
for every minute), or a set of values separated by commas (e.g., 0,30
for midnight and 30 minutes past the hour). The *
character can be used to match any value.
Once you have edited the crontab
file and saved your changes, cron
will automatically run the tasks you have specified at the specified intervals. You can use the crontab -l
command to view the current cron jobs, and the crontab -e
command to edit the crontab
file.