怎么设置linux定时任务
时间: 2024-04-30 16:22:54 浏览: 65
要设置Linux定时任务,可以使用crontab命令。以下是设置定时任务的步骤:
1. 打开终端并输入以下命令以编辑crontab文件:
```bash
crontab -e
```
2. 在编辑器中添加定时任务。每行表示一个定时任务,格式如下:
```
* * * * * command-to-be-executed
- - - - -
| | | | |
| | | | ----- Day of the week (0 - 7) (Sunday is both 0 and 7)
| | | ------- Month (1 - 12)
| | --------- Day of the month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
```
例如,以下是每小时运行一次的定时任务:
```
0 * * * * command-to-be-executed
```
3. 保存文件并退出编辑器。
4. 使用以下命令查看当前的定时任务列表:
```bash
crontab -l
```
5. 如果需要删除一个定时任务,可以使用以下命令:
```bash
crontab -r
```
注意:要确保定时任务的命令路径正确,并且定时任务的执行权限正确设置。
阅读全文
相关推荐












