在Linux系统中,crontab是一个用于设置周期性被执行的任务的工具。要设置间隔时间执行任务,您需要编辑crontab文件。以下是编辑crontab文件的步骤:
打开终端。
输入以下命令以编辑当前用户的crontab文件:
crontab -e
如果您是root用户,请使用以下命令:
sudo crontab -e
* * * * * /path/to/command arg1 arg2
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday to Saturday; 7 is also Sunday)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
要设置间隔时间执行任务,您可以使用以下方法:
* * * * * /path/to/command arg1 arg2
0 * * * * /path/to/command arg1 arg2
0 0 * * * /path/to/command arg1 arg2
0 0 * * 0 /path/to/command arg1 arg2
0 0 1 * * /path/to/command arg1 arg2
注意:请确保将/path/to/command arg1 arg2替换为您要执行的实际命令及其参数。