温馨提示×

ubuntu定时器怎么停止任务

小樊
43
2026-10-21 13:56:11
栏目: 智能运维

在 Ubuntu 里“定时器”通常有两种常见含义,停止方式不一样:


一、如果是 systemd 定时器(systemd timer)

1. 查看当前定时器

systemctl list-timers

2. 停止某个定时器(立即失效,重启后可能恢复)

sudo systemctl stop your-timer.timer

3. 禁用定时器(开机不再自动启动)

sudo systemctl disable your-timer.timer

4. 同时停止并禁用(最常用)

sudo systemctl disable --now your-timer.timer

5. 如果任务正在跑(对应的 service)

sudo systemctl stop your-service.service

二、如果是 cron 定时任务(crontab)

1. 查看当前任务

crontab -l

2. 编辑并删除任务

crontab -e

删除对应行后保存即可。

3. 停止 cron 服务(不推荐,会影响所有任务)

sudo systemctl stop cron

4. 禁用某个用户的 cron

sudo crontab -r -u username

三、如果是 at 一次性任务

查看任务

atq

删除任务

atrm 任务编号

四、如果是 自己写的脚本循环 / sleep

可以用:

pkill -f your-script.sh

或

kill PID

如果你能告诉我:

  • 用的是 systemd / cron / at
  • 任务名或脚本名

我可以给你精确的一条命令。

0 踩