温馨提示×

ubuntu定时器怎么禁用

小樊
33
2026-10-06 23:57:52
栏目: 智能运维

在 Ubuntu 里“定时器”通常指 systemd 的 timer(还有可能是 cron 或 anacron)。下面分别说明。


一、禁用 systemd 定时器(最常见)

1. 查看有哪些 timer

systemctl list-timers --all

2. 禁用某个 timer(以 apt-daily.timer 为例)

sudo systemctl disable --now apt-daily.timer
  • disable:开机不再启动
  • --now:立即停止当前运行

3. 只停止不禁用(临时)

sudo systemctl stop apt-daily.timer

4. 彻底屏蔽(防止被依赖启用)

sudo systemctl mask apt-daily.timer

恢复:

sudo systemctl unmask apt-daily.timer

二、禁用 cron 定时任务

1. 用户级 cron

crontab -l        # 查看
crontab -r        # 删除当前用户所有任务

或编辑:

crontab -e

注释掉对应行(# 开头)

2. 系统级 cron

ls /etc/cron.d/
ls /etc/cron.daily/

直接删或改名:

sudo mv /etc/cron.daily/foo /etc/cron.daily/foo.disabled

三、禁用 anacron(桌面/服务器常见)

sudo systemctl disable --now anacron.timer

或:

sudo apt remove anacron

四、常见例子

禁用自动更新定时器:

sudo systemctl disable --now apt-daily.timer
sudo systemctl disable --now apt-daily-upgrade.timer

如果你能告诉我具体是哪个定时器(比如 apt-daily、snap、logrotate 或某个自定义服务),我可以给你更精确的命令。

0 踩