A crontab (cron tables) is a configuration file that specifies shell commands to run periodically on a given schedule. The commands in a crontab file (also known as a “cron job”) are executed by the cron daemon, a built-in Linux utility that runs processes on your system at a scheduled time.
Each line in a crontab file represents a separate cron job and follows a specific format, consisting of six fields separated by spaces:
* * * * * command
The fields represent the following:
- Minute (0-59)
- Hour (0-23)
- Day of the month (1-31)
- Month (1-12)
- Day of the week (0-6, with 0 being Sunday)
- The command to be run
The asterisks in the first five fields indicate that the command should be run every minute, every hour, every day of the month, every month, and every day of the week, respectively.
To edit your crontab file, you can use the crontab -e command, which will open the file in a text editor. When you are finished editing the file, save and exit the editor to activate the changes.
To run a command at 4:00am every day, the entry in the crontab file would be:
0 4 * * * command
To run a command every Monday at 6:00am, the entry would be:
0 6 * * 1 command
To run a command every 15 minutes using a crontab, you can use the following entry:
*/15 * * * * command
To run a command every 4 hours using a crontab, you can use the following entry:
0 */4 * * * command
To run a command at 3:15am every day using a crontab, you can use the following entry:
15 3 * * * command