← All tips

Keep the Mac awake from Terminal

caffeinate stops the Mac from sleeping for as long as you say, or until a command finishes.

When a long download, backup or build must not be interrupted by sleep, Terminal has a built-in answer:

caffeinate

Leave it running and the Mac will not idle-sleep; press ⌃ + C to stop it. The variants are more useful:

caffeinate -t 3600      # stay awake for one hour
caffeinate -d           # keep the display on as well
caffeinate -i make      # stay awake until the command finishes
caffeinate -w 1234      # stay awake until process 1234 exits

The last two are the ones to remember: the Mac stays awake exactly as long as the job needs, and returns to its normal sleep settings by itself when it ends.

-s keeps the whole system awake, but only while the Mac is on power. man caffeinate lists every option.


Related tips