在 Linux 系统中,可以通过以下方法实现定时关机:
shutdown
命令(推荐)sudo shutdown -h +30 # 30分钟后关机
sudo shutdown -h 23:00 # 晚上11点关机
sudo shutdown -h now # 立即关机
at
命令(单次任务)echo "shutdown -h now" | at 23:00 # 晚上11点关机
cron
(周期性任务)编辑 crontab:
crontab -e
添加一行(例如每天23:00关机):
0 23 * * * /sbin/shutdown -h now
sudo shutdown -c # 取消已计划的关机
-h
:halt(停止系统),等同于关机+m
:m分钟后执行(如 +30 表示30分钟后)hh:mm
:指定具体时间选择哪种方式取决于你的需求:
- 单次临时任务用 shutdown
或 at
- 周期性任务用 cron