How to Use Crontab in Linux

In Linux, the crontab command can be used to set up scheduled tasks. Here are the basic usage methods for crontab.

  1. Open the terminal and enter the following command to edit the crontab file for the current user:
crontab -e
  1. Add the scheduled task to be executed in the editor in the following format.
* * * * * command

The first one represents minutes, the second one represents hours, the third one represents the date, the fourth one represents the month, the fifth one represents the day of the week, and command represents the command to be executed.

  1. Once the editing is done, press Ctrl + X, then press Y to save and exit the editor.
  2. View the crontab tasks of the current user using the following command:
crontab -l
  1. To remove all crontab tasks for the current user, you can use the following command:
crontab -r

It’s important to note that the time format in crontab is based on a 24-hour clock, with each field separated by a space. You can also use the “man crontab” command to find more detailed information about the crontab command.

bannerAds