Files
nexus/wiki/concepts/caffeinate.md
2026-04-17 08:38:12 +08:00

52 lines
1.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: "caffeinate"
type: concept
tags: [macos, power-management, command-line]
date: 2026-04-17
---
## Definition
caffeinate 是 macOS 内置工具,用于临时阻止系统进入睡眠状态。与 pmset 不同caffeinate 不修改系统设置,仅在运行时有效,按 Ctrl+C 停止后系统恢复默认睡眠行为。
## Installation
```bash
# macOS 内置,无需安装
```
## Usage
```bash
# 防止显示器睡眠
caffeinate -d
# 防止系统空闲时睡眠
caffeinate -i
# 防止系统睡眠
caffeinate -s
# 模拟用户活动(防止睡眠)
caffeinate -u
# 组合使用(常用)
caffeinate -d -i -s
# 保持唤醒(按 Ctrl+C 停止)
caffeinate -d -i -s
```
## Parameters
| 参数 | 作用 |
|------|------|
| `-d` | 防止显示器睡眠 |
| `-i` | 防止系统空闲时睡眠 |
| `-s` | 防止系统睡眠 |
| `-u` | 模拟用户活动(防止睡眠) |
## Use Cases
- 临时运行需要持续运行的任务(如大型下载、安装)
- 演示或展示时需要保持屏幕常亮
- 不希望修改系统电源设置时的临时方案
## Related Concepts
- [[pmset]]:永久修改系统电源设置的工具
- [[WOL (Wake on LAN)]]:网络唤醒功能