Files
nexus/wiki/concepts/pmset.md

75 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "pmset"
type: concept
tags: [macOS, 电源管理, 系统管理]
---
# pmset
> macOS 系统电源管理命令行工具,用于查询和修改 macOS 的电源设置sleep/displaysleep/standby/hibernatemode/womp
## 概述
`pmset` 是 macOS 内置的电源管理工具,可查看和配置系统睡眠、显示器睡眠、待机、休眠等行为。在 Mac Mini 作为 Home Server无显示器运行时正确的 `pmset` 配置是确保 7×24 持续可访问的关键。
## 核心参数
### 查询命令
| 命令 | 作用 |
|------|------|
| `pmset -g` | 显示当前所有电源设置 |
| `pmset -g sleep` | 显示睡眠相关设置 |
| `pmset -g displaysleep` | 显示显示器睡眠设置 |
### 设置命令(永久生效)
| 命令 | 作用 |
|------|------|
| `pmset -a sleep 0` | 禁止系统睡眠 |
| `pmset -a displaysleep 0` | 禁止显示器关闭 |
| `pmset -a standby 0` | 禁止待机模式 |
| `pmset -a hibernatemode 0` | 禁止休眠(内存保存到磁盘) |
| `pmset -a womp 1` | 启用网络唤醒WOL |
### 参数作用域
| 参数 | 含义 |
|------|------|
| `-a` | 应用于所有电源模式(电池 + 电源适配器) |
| `-b` | 仅电池模式 |
| `-c` | 仅电源适配器模式 |
## Home Server 最佳实践
将以下命令写入启动脚本或通过 MDM 配置:
```bash
sudo pmset -a sleep 0
sudo pmset -a displaysleep 0
sudo pmset -a standby 0
sudo pmset -a hibernatemode 0
sudo pmset -a womp 1
```
## 与 Linux 对应关系
| macOS (pmset) | Linux (systemd-logind) |
|---|---|
| `sleep 0` | `HandleLidSwitch=ignore` |
| `displaysleep 0` | 无直接对应Linux 无显示器概念) |
| `standby 0` | `AllowSuspend=no` |
| `hibernatemode 0` | `HibernateMode=off` |
| `womp 1` | 无直接对应(需 ethtool 配置 WoL |
## 相关概念
- [[caffeinate]] — 临时防止睡眠的工具,不修改系统设置
- [[Wake-on-LAN]] — 网络唤醒,与 `womp` 参数相关
- [[系统睡眠管理]] — 操作系统电源管理的通用概念
- [[Headless 服务器]] — 无显示器的服务器pmset 配置的目标场景
## 相关实体
- [[Mac Mini M4]] — pmset 的典型应用平台