Modern Macs are incredibly aggressive about power management. Whether you are using a battery-powered MacBook or a desktop Mac Mini, the operating system is designed to turn off the display and put the processor to sleep after a few minutes of inactivity. While excellent for the environment and your electric bill, this behavior is infuriating when you are downloading a 100GB video game, exporting a massive 4K video project in the background, or running a lengthy system backup.
If the Mac goes to sleep, the hard drive spins down and the network connection drops, instantly killing your multi-hour download. While you could dig into the System Settings to permanently alter your energy preferences, there is a much faster, temporary solution built directly into macOS.
The Built-in Solution: The “caffeinate” Command
macOS is built on a Unix foundation, meaning it includes a powerful Terminal application. Apple specifically engineered a tiny, hidden command-line utility designed solely to prevent the system from sleeping. Appropriately, this command is called caffeinate.
When you run this command, it forces your Mac to stay awake indefinitely, ignoring all user inactivity timers until you explicitly tell it to stop.
How to Use the Caffeinate Command
You do not need any coding experience to use this tool; it is a single word.
- Open the Terminal application. (You can find it by pressing
Command + Spacebarto open Spotlight search, typing “Terminal”, and pressing Enter). - In the black Terminal window, type the following word in all lowercase letters:\n
caffeinate - Press Enter.
Nothing visually dramatic will happen, but the cursor will move to the next line and blink, waiting. As long as that Terminal window remains open and the command is running, your Mac will not go to sleep, even if you close the lid on your MacBook (provided it is plugged into a power adapter and an external display).
You can now minimize the Terminal window, walk away from your computer, and let your massive download finish overnight.
How to Stop the Caffeinate Command
When your download is finally complete, you must turn off the caffeinate utility so your Mac can return to its normal power-saving behavior.
- Bring the Terminal window back up on your screen.
- Press and hold the Control key, then press the letter C (
Control + C).
This is the universal Unix command to kill a running process. The Terminal will immediately stop the caffeinate command and return you to the standard command prompt. You can now safely close the Terminal window, and your Mac will go to sleep automatically based on your normal system preferences.
Setting a Specific Time Limit
If you know your download will take exactly two hours, and you want the Mac to automatically go to sleep after that time without you needing to manually kill the command, you can add a timer.
Use the -t flag, followed by the number of seconds you want the Mac to stay awake. For example, to keep the Mac awake for exactly 2 hours (7200 seconds), you would type:
caffeinate -t 7200
The command will run silently for two hours, preventing sleep. The exact second the timer expires, the command will terminate itself, and the Mac will be allowed to drift back to sleep normally. This is a very elegant solution to a common macOS annoyance.