Sitemap
Amith Chandrappa

Amith Chandrappa

VP, Engineering

CRONTAB

2 min readDec 7, 2022

Crontab, also known as the “cron table,” is a powerful Linux utility that allows users to schedule tasks to be automatically performed at specified times or intervals. This can be useful for a wide range of purposes, such as automating backups, performing maintenance tasks, or running regular reports.

To use crontab, you first need to open a terminal window and log in as the root user. Once you are logged in, you can use the “crontab” command to manage your cron jobs. To create a new cron job, use the following command:

crontab -e

This will open the crontab editor, where you can specify the details of your cron job. Each cron job is represented by a single line in the editor, with the following format:

minute hour day-of-month month day-of-week command

Each field in this format represents a different aspect of the cron job. The “minute” field specifies the minute of the hour when the job should be run, the “hour” field specifies the hour of the day, and so on. For example, the following cron job would run the “my_script.sh” script at 10:15 every day:

15 10 * * * /path/to/my_script.sh

Alternatively, you can use special symbols in place of specific values in the fields. For example, the “*” symbol can be used to match any value, so the following cron job would run the “my_script.sh” script every hour on the hour:

0 * * * * /path/to/my_script.sh

Once you have entered the details of your cron job, save the file and exit the editor. Your cron job will now be scheduled to run at the specified times.

Get Amith Chandrappa’s stories in your inbox

Join Medium for free to get updates from this writer.

To view the list of all cron jobs currently scheduled on your system, use the following command:

crontab -l

To edit an existing cron job, use the following command:

crontab -e

This will open the crontab editor again, allowing you to modify the details of the cron job. Once you have made your changes, save the file and exit the editor.

To remove a cron job, use the following command:

crontab -r

This will remove all of the cron jobs currently scheduled on your system. If you only want to remove a specific cron job, use the following command instead:

crontab -l | grep -v 'my_script.sh' | crontab -

This will list all of the cron jobs on your system, remove the job for “my_script.sh,” and then save the resulting list as the new set of cron jobs.

In summary, crontab is a powerful Linux utility that allows you to automate tasks and schedule them to be performed at specific times. By using the commands discussed above, you can easily manage your cron jobs and make the most of this useful tool.

--

--