Guide
caffeinate: keep your Mac awake from Terminal

caffeinate is built into macOS, it's reliable and it's free. If you're in the Terminal anyway, it's often the fastest way to keep your Mac awake. Here's everything you need, from the quick one-liner to running it in the background.
The quick start
Open Terminal, type one line, hit Enter. As long as the window stays open, caffeinate keeps the Mac awake. ctrl+C stops it.
caffeinate | With no option it prevents system sleep, exactly like -i. |
|---|---|
caffeinate -i | Prevents idle sleep. The screen may dim, the machine keeps working. |
caffeinate -d | Keeps the display awake, and with it the system. Nothing goes dark. |
caffeinate -m | Prevents the disk from going to sleep. |
caffeinate -s | Keeps the system awake, but only on AC power. |
caffeinate -u | Declares user activity: a dark display turns on and stays on. Without -t this only lasts five seconds. |
caffeinate -dimsu | The keep-everything-awake combo. Handy, but blunter than needed. |
With a time limit instead of forever
Few people know the -t option, yet it's the most useful one. The number after it is seconds. caffeinate -i -t 3600 keeps the Mac awake for exactly one hour, then lets it sleep again.
| 30 minutes | -t 1800 |
|---|---|
| 1 hour | -t 3600 |
| 2 hours | -t 7200 |
| 4 hours | -t 14400 |
| 8 hours | -t 28800 |
You don't have to do the math yourself, the shell does it: caffeinate -i -t $((4*60*60)) is four hours.
Until a specific time
“Until 9 tomorrow morning” works too, with a small detour through the date command:
caffeinate -i -t $(( $(date -v+1d -v9H -v0M -v0S +%s) - $(date +%s) ))
The line works out the seconds until 9:00 tomorrow and hands them to -t. For 11 p.m. today, drop -v+1d and write -v23H instead of -v9H.
Only while a command runs
Handy for scripts: append the actual command. The Mac then stays awake exactly as long as the task takes and sleeps again on its own afterwards.
caffeinate -i ./my-backup.sh
If the task is already running, attach to its process ID with -w. caffeinate then waits until that process ends:
caffeinate -i -w $(pgrep -n rsync)
pgrep -n rsync finds the process ID of the most recently started rsync. You can also look up any app's number in Activity Monitor, in the “PID” column.
Keep it running in the background
Normally caffeinate ends with the Terminal window. To keep it going after you close the window, start it like this:
nohup caffeinate -i -t 7200 >/dev/null 2>&1 & disown
Now you can close the window and the Mac stays awake for two hours. To stop it early, run killall caffeinate.
How to check that it works
pmset -g assertions lists every active lock against sleep. While caffeinate runs, it shows up there with its process ID, as PreventUserIdleSystemSleep for -i and PreventUserIdleDisplaySleep for -d. The same list also tells you which other app is currently blocking sleep.
Where caffeinate hits its limits
As good as the command is, day to day it grates in a few spots:
- You can't see whether it's still running or how long is left. No status, no countdown.
- For “just for a moment” you won't type it every time, especially if you don't live in the Terminal anyway.
- There's no option that specifically keeps the network connection awake. And switching modes always means stopping and restarting.
- Lid closed means game over. Close a MacBook and none of the options help, not even
-s. Closing the lid is a separate reason to sleep. What helps then is in Keep your MacBook awake with the lid closed.
caffeinate, settings or an app?
- caffeinate fits if you work in the Terminal anyway or want to safeguard scripts.
- System Settings fit if the Mac lives on a desk and should never sleep.
- A menu bar app fits if you often need it in between, with a timer and no typing. All three routes compared are in Keep your Mac awake without Terminal.
Common questions
Does caffeinate need admin rights?
No. Any user can run the command without sudo.
Does caffeinate work on Macs with Apple silicon?
Yes. The command is part of macOS and behaves the same on Intel and Apple silicon Macs.
How do I stop caffeinate?
In the open window with ctrl+C, in the background with killall caffeinate. With -t it ends on its own when the time is up.
caffeinate, but as a switch
Helmlet brings keeping awake into the menu bar: system, display and network individually, each with a timer and countdown. Afterwards everything returns to normal automatically.
Get HelmletMore: Keep your Mac awake without Terminal and Keep your MacBook awake with the lid closed.