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:
- Open the Terminal window.
- Enter the command: crontab -e
- 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.
- 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.
- After finishing editing the task, save and exit the editor.
- You can use the command “crontab -l” to view the current list of scheduled tasks.
- 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.