Fastest option: run caffeinate -i to prevent idle system sleep until you press Control-C. To keep the Mac awake only while another command runs, put that command after caffeinate.
Basic examples
Keep the Mac awake until you stop it
caffeinate -i
Leave that Terminal tab open. Press Control-C when the job is done.
Keep the Mac awake for one hour
caffeinate -i -t 3600
The timeout is measured in seconds, so 3,600 seconds is one hour.
Keep the Mac awake while a command runs
caffeinate -i -- your-long-command
The assertion ends when the command exits. This is cleaner than starting a separate keep-awake process and remembering to stop it later.
Keep a download running
caffeinate -i -- curl -L -O https://example.com/large-file.zip
What the flags mean
| Flag | Effect |
|---|---|
-i | Prevents idle system sleep. |
-d | Prevents idle display sleep. |
-m | Prevents idle disk sleep. |
-s | Prevents system sleep while on AC power. |
-t | Applies a timeout in seconds. |
-w | Waits for a process ID and holds the assertion until that process exits. |
You can read the exact documentation installed on your Mac with:
man caffeinate
Does caffeinate work with the lid closed?
Not by itself. Apple's power-management documentation distinguishes idle sleep from forced sleep and names closing a laptop lid as forced sleep. Documented sleep assertions prevent idle sleep, not forced lid-close sleep. See Apple Technical Q&A QA1340.
If you need the Mac to continue without an external display after the lid closes, read the closed-lid Mac guide. Caffeine Toggle handles both idle assertions and the separate clamshell state behind one menu-bar mug.
How to see active assertions
pmset -g assertions
Look for the caffeinate process and the sleep categories it owns. This command is useful when you forgot which Terminal tab started the assertion.
How to stop caffeinate
If it is running in the foreground, press Control-C. If you started it elsewhere and need to stop every process named caffeinate, you can use:
killall caffeinate
Be careful: that also stops assertions started by other apps or scripts under your account.
Do not confuse awake with cool. A Mac that refuses sleep can keep producing heat. Do not place it in a bag or on bedding while a keep-awake command is active.
Prefer a switch over Terminal?
Download the ZIP, open it, and drag Caffeine Toggle into Applications. On first launch, Control-click the app and choose Open; if blocked, use System Settings → Privacy & Security → Open Anyway. This build is signed with an Apple Development certificate and is not yet notarized.
Download Caffeine Toggle 3.0.1