How to keep your Mac awake with caffeinate
macOS ships with a built-in command called caffeinate that holds a software assertion preventing your Mac from sleeping — for as long as you leave it running. It's a precise, temporary tool: no permanent settings changed, no sudo required. This guide covers every useful variant, plus what to do when you don't want to keep a Terminal window open.
The basic command
Open Terminal (Applications > Utilities, or Spotlight: Cmd Space, type Terminal) and run:
# keep the Mac awake until you press Ctrl+C
caffeinate
The cursor will sit there doing nothing visible — that's correct. The command is running and holding the system awake. Press Ctrl+C to stop it. As soon as you stop it, normal sleep timers resume.
Caffeinate for a set duration
The -t flag takes a duration in seconds. This is the most useful form: you kick it off and forget about it, then it expires automatically.
# stay awake for 30 minutes (1800 seconds)
caffeinate -t 1800
# stay awake for 1 hour (3600 seconds)
caffeinate -t 3600
# stay awake for 2 hours (7200 seconds)
caffeinate -t 7200
Caffeinate flags — what each one does
Without any flags, caffeinate prevents idle system sleep but the display can still sleep. Add flags to widen what it blocks:
-d— prevent display sleep. Use this for presentations or screen shares.-i— prevent idle system sleep (the default behaviour, stated explicitly).-s— prevent sleep when on AC power only. Ignored on battery.-m— prevent the disk from sleeping. Rarely needed but useful for long disk operations.
You can combine flags. For a one-hour session where you want both the display and the system awake:
# prevent display sleep AND system idle sleep for 2 hours
caffeinate -di -t 7200
Running caffeinate in the background
The drawback of the basic command is that it ties up your Terminal window — if you close the window, caffeinate stops. To run it in the background and keep your prompt free:
# run in background, stay awake 1 hour
caffeinate -t 3600 &
Bash will print something like [1] 48291 — that's the job number and PID. To stop it early:
# stop by job number (the [1] from the output above)
kill %1
# or stop by PID
kill 48291
If you've lost track of the PID, find it with:
# find running caffeinate processes
pgrep caffeinate
Caffeinate while a command runs
A tidy pattern: wrap a long-running command with caffeinate so the Mac stays awake exactly as long as the command takes, then sleeps normally:
# stay awake while a big rsync runs, then resume normal sleep
caffeinate rsync -av ~/Movies /Volumes/Backup
This is the cleanest approach for backups, video exports, or large uploads — no timer to guess, and no manual cleanup needed afterwards.
The limits of caffeinate
caffeinate is a Terminal tool, which means it requires you to keep either a Terminal window open (or remember the background job PID). It has no GUI, no status in the menu bar, and no easy way to tell at a glance whether it's still running. For occasional use that's fine. For something you do regularly — before a long meeting, a download, a remote connection — it becomes friction.
Mainspring has a built-in Caffeinate feature with preset durations — 30 minutes, 60 minutes, 120 minutes, or a custom duration you type in. One click to start, one click to stop. No Terminal window to leave open, no PID to track, no timer math. It's visible from the Mainspring menu so you always know whether caffeinate is active.
Try Mainspring free →Signed & notarized by Apple · 1-day free trial · $29 once
Caffeinate vs. changing pmset sleep settings
caffeinate and pmset both prevent sleep, but they work differently. caffeinate holds a temporary assertion — the moment it exits, normal sleep resumes with no cleanup needed. pmset -a sleep 0 changes a persistent system setting that stays until you change it back. For short-lived "keep me awake right now" needs, caffeinate is cleaner. For a Mac that should never sleep (a server, a download box), pmset is the right tool. See our guide on stopping your Mac from sleeping permanently for the pmset approach.