用 shutdown 定时或立即关机、重启 Mac

立即或 N 分钟后关机、重启 Mac,还能随时取消待执行的关机任务。

macOS重启终端关机与重启中风险
执行 sudo shutdown -r now 立即重启,或 sudo shutdown -h +30 在 30 分钟后关机。

01命令

命令
$ sudo shutdown -h +30   # halt in 30 minutes; sudo shutdown -r now restarts now

02作用说明

shutdown 支持 +分钟数 的延迟参数,执行前会向所有登录用户广播警告,非常适合「导出完成后自动关机」这类场景。-h 表示关机断电,-r 表示重启。延迟关机等待期间再次运行 shutdown 可查看剩余时间,用 sudo killall shutdown 则可取消。

03风险

风险中风险
使用条件Requires an administrator password.
!注意: 未保存的文档可能丢失或阻止关机;共享 Mac 上请先提醒其他用户。

04撤销

撤销
$ sudo killall shutdown

05来源

  • shutdown(8) man page
    manpagez.com · technical · 2026-09-17
    依据: The shutdown man page shows -h (halt/power-off), -r (reboot) and the +time argument for a delayed shutdown, with a broadcast warning to logged-in users.
  • shutdown - Halt, Power-off or Reboot the Machine
    SS64 · technical · 2026-09-17
    依据: Documents shutdown -h to halt, -r to reboot, and the +time form for scheduling the shutdown N minutes in the future.

最后验证: 2026-09-19 · 分类: 系统与设置

06相关方案