How to Automatically Keep Your Mac Awake Using the Terminal Command Caffeinate

By default, macOS is aggressively tuned to save battery life. If you step away from your computer for a few minutes, the screen will dim, the hard drive will spin down, and the Mac will go to sleep. This is fantastic for a laptop on an airplane, but it is a disaster if you are halfway through downloading a massive 50GB video game file, or if you are rendering a complex video project in the background. Instead of digging through System Settings to temporarily disable your sleep schedule (and forgetting to turn it back on later), you can keep your Mac awake with a brilliant terminal command called caffeinate.

How to Use the Caffeinate Command

The caffeinate utility is built directly into the core of macOS. It does exactly what it sounds like: it feeds your computer digital caffeine, preventing it from sleeping under any circumstances.

  1. Open the Terminal app on your Mac (you can find it by pressing Cmd + Space and searching for “Terminal”).
  2. In the terminal window, type the following command:
    caffeinate
  3. Press Enter.

The terminal will drop down to a blank line and just sit there. There is no success message. However, as long as that Terminal window remains open and the command is running, your Mac will absolutely refuse to go to sleep. Your screen may still turn off to save power, but the processor, hard drive, and network connections will remain fully active.

To turn the caffeine off and allow your Mac to sleep normally again, go back to that Terminal window and press Control + C on your keyboard to cancel the active command.

How to Set a Specific Timer

If you know your download is going to take exactly two hours, you do not have to remember to manually cancel the command later. You can tell caffeinate to run for a specific duration using the -t (time) flag.

The command calculates time in seconds. For example, one hour is 3600 seconds. To keep your Mac awake for exactly one hour, type:

caffeinate -t 3600

Press Enter. You can now walk away from your desk. Your Mac will stay awake for the next 60 minutes, ensuring your download finishes, and then it will automatically return to its normal sleep schedule.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.