Debian系统中,systemd
是系统和服务管理器,它提供了定时器的功能。以下是一些常用的systemd
定时器命令:
启动定时器
sudo systemctl start <timer-name>.timer
停止定时器
sudo systemctl stop <timer-name>.timer
重启定时器
sudo systemctl restart <timer-name>.timer
查看定时器状态
sudo systemctl status <timer-name>.timer
启用定时器(使其在启动时自动运行)
sudo systemctl enable <timer-name>.timer
禁用定时器(防止其在启动时自动运行)
sudo systemctl disable <timer-name>.timer
重新加载定时器配置
sudo systemctl daemon-reload
列出所有定时器
systemctl list-timers --all
列出所有已启用的定时器
systemctl list-timers --type=timer --all
查看特定定时器的详细信息
systemctl show <timer-name>.timer
查看定时器关联的服务
systemctl show <timer-name>.timer -p FragmentPath
/etc/systemd/system/
目录下,文件名格式为<timer-name>.timer
。<service-name>.service
。假设你有一个名为backup.timer
的定时器,你可以使用以下命令来管理它:
# 启动定时器 sudo systemctl start backup.timer # 停止定时器 sudo systemctl stop backup.timer # 查看定时器状态 sudo systemctl status backup.timer # 启用定时器 sudo systemctl enable backup.timer # 禁用定时器 sudo systemctl disable backup.timer # 列出所有定时器 systemctl list-timers --all # 查看特定定时器的详细信息 systemctl show backup.timer
通过这些命令,你可以方便地管理和监控Debian系统中的定时任务。