Linux Crontab: Schedule Tasks Easily

To set up scheduled tasks in Linux systems, you can use the crontab command. The specific steps are as follows:

  1. Open the Terminal window.
  2. Enter the command: crontab -e
  3. If it’s the first time you’re setting up a scheduled task, the system will prompt you to choose a text editor (such as nano, vim, etc.), so choose one that you’re familiar with.
  4. Add the scheduled task you want to perform in the open file, with the following format:
* * * * * command
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

In the template, the asterisk (*) represents all possible values. For example, “* * * *” indicates that the task is executed every minute.

  1. After finishing editing the task, save and exit the editor.
  2. You can use the command “crontab -l” to view the current list of scheduled tasks.
  3. To delete all scheduled tasks, you can use the command crontab -r.

It is important to note that scheduled tasks will create a file named .cron in the user’s home directory, which contains the user’s scheduled tasks.

bannerAds