在 Ubuntu 中,你可以使用 systemd
或 cron
来设置定时任务。根据你使用的定时任务类型,停止定时任务的方法也有所不同。
systemd
定时器如果你使用的是 systemd
定时器,可以通过以下步骤停止它:
列出所有定时器:
systemctl list-timers --all
停止特定的定时器:
sudo systemctl stop your-timer-name.timer
禁用定时器(防止它自动启动):
sudo systemctl disable your-timer-name.timer
重新启用定时器(如果需要):
sudo systemctl enable your-timer-name.timer
cron
定时任务如果你使用的是 cron
定时任务,可以通过以下步骤停止它:
编辑 crontab 文件:
crontab -e
注释掉或删除定时任务行:
找到你要停止的定时任务行,前面加上 #
号进行注释,或者直接删除该行。
保存并退出编辑器:
按 Ctrl + X
,然后按 Y
确认保存,最后按 Enter
退出。
假设你有一个 systemd
定时器名为 my-timer.timer
,你可以这样停止它:
sudo systemctl stop my-timer.timer
sudo systemctl disable my-timer.timer
如果你有一个 cron
定时任务,你可以这样停止它:
crontab -e
找到类似以下的行并注释掉或删除:
* * * * * /path/to/your/script.sh
保存并退出编辑器。
通过这些步骤,你可以轻松地停止 Ubuntu 中的定时任务。