Guide

caffeinate: keep your Mac awake from Terminal

Updated October 2026 · 8 min read

caffeinate: keyboard and coffee cup as a symbol for the Terminal command

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.

caffeinateWith no option it prevents system sleep, exactly like -i.
caffeinate -iPrevents idle sleep. The screen may dim, the machine keeps working.
caffeinate -dKeeps the display awake, and with it the system. Nothing goes dark.
caffeinate -mPrevents the disk from going to sleep.
caffeinate -sKeeps the system awake, but only on AC power.
caffeinate -uDeclares user activity: a dark display turns on and stays on. Without -t this only lasts five seconds.
caffeinate -dimsuThe 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:

caffeinate, settings or an app?

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 Helmlet

More: Keep your Mac awake without Terminal and Keep your MacBook awake with the lid closed.

← Back to the blog