Kirti Kumar Sahu · October 6, 2026 · 12:00 · 6 min read
A long task was running on my Mac recently, the kind that needs an hour or so and can't be interrupted. The usual fix is to open System Settings, raise the sleep timer, and then (if you're anything like me) forget to change it back for a month. A quick search turned up a better answer that had been sitting in macOS all along: caffeinate.
It's a small command, but it changed how I think about the Mac's terminal. My last post was about modern CLI tools you install. This one is about the tools you don't have to install, because Apple ships them, barely documents them, and most developers never find them.
caffeinate stops the Mac from sleeping, and the useful part is how you scope it. You don't change a setting. You wrap the command, and the Mac goes back to normal the moment the job ends.
-i — prevent idle sleep. The one you want for builds, downloads, training runs and long test suites.-d — keep the display on. Useful for dashboards or a presentation that shouldn't dim.-m — keep the disk awake when it would otherwise idle.-s — keep the whole system awake, but only while plugged in.-u — declare the user active, which wakes the display; it times out after five seconds unless you add -t.-t <seconds> — a time limit, after which normal sleep behaviour returns.-w <pid> — wait for a process and stay awake until it exits.caffeinate -i npm run build # awake only while the build runs
caffeinate -dims -t 7200 # fully awake for two hours
caffeinate -i -w $(pgrep -f train.py) # attach to a job that's already running
The third form is the one I like most. You started something, then realised it will outlast your sleep timer. You don't need to restart it. Just attach caffeinate to its process ID.
If you want to see it working, pmset -g assertions lists every process currently keeping the Mac awake. Run it alongside caffeinate and you'll see your assertion in the list. It's also the command to reach for when a Mac refuses to sleep and you want to know which app is responsible.
pbcopy / pbpaste — the clipboard as a pipe. cat ~/.ssh/id_ed25519.pub | pbcopy replaces opening a file to select and copy. pbpaste | jq . pretty-prints JSON you just copied out of a network tab.open — the bridge to the GUI. open . shows the current folder in Finder, open -a "Visual Studio Code" file.js picks the app, and open https://... sends a URL to the default browser.qlmanage -p — Quick Look from the terminal. Preview an image or PDF without leaving the shell.xattr -d com.apple.quarantine — the fix for "app is damaged". Gatekeeper tags downloaded files. When a trusted CLI binary or app won't open, removing that attribute is usually the answer. Do this only for software you trust.mdfind — Spotlight on the command line. mdfind -name package.json searches the Spotlight index instead of walking the disk, so it finishes before find has got through node_modules.mdls — a file's metadata, the same data Spotlight sees.lsof -i :3000 — who owns this port. The fastest way to find the dev server that didn't shut down cleanly.log stream --predicate 'process == "MyApp"' — live system logs, filtered. Far more usable than Console.app when you already know which process you care about.sudo powermetrics --samplers cpu_power,gpu_power — where the battery is going, measured rather than guessed.system_profiler SPHardwareDataType — hardware details for bug reports, without the About This Mac screenshot.networkQuality — Apple's own speed test (macOS 12 and later). It reports upload and download capacity and responsiveness, with no ad-heavy website in between.ipconfig getifaddr en0 — your local IP. This is what you need when testing a local build on a phone over Wi-Fi.sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder — flush DNS. It's worth keeping as an alias for when you've edited /etc/hosts or moved a record and the Mac is still holding on to the old answer.sips -Z 800 *.png — resize images in bulk, keeping the aspect ratio. Handy for README screenshots and app-store assets.textutil -convert html doc.docx — document conversion between docx, rtf, html and plain text.screencapture -x -T 3 shot.png — a silent, delayed screenshot, scriptable for docs and visual checks.plutil -convert json file.plist -o - — read plists as JSON, which makes Apple config files scriptable with jq.say — spoken alerts. npm test; say "tests finished" means you can go and make tea.osascript -e 'display notification "Deploy finished" with title "CI"' — a native notification from any script.shortcuts run "My Shortcut" — Apple Shortcuts from the shell, so personal automations can join a build pipeline.defaults write — hidden settings. For example, defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder. A dotfiles repo full of defaults commands is how you set up a new Mac in one go.security find-generic-password -s "name" -w — secrets from Keychain, which is a better home for a local API token than a .env file that might get committed.Put a few of these together and you get the line I now use most:
caffeinate -i npm run build && say "build done"
It keeps the Mac awake for the build, then tells you out loud when it's finished. No settings changed, nothing to undo.
None of this is a reason to stop installing good tools. mdfind doesn't replace ripgrep for searching code, networkQuality isn't a network diagnostic suite, and caffeinate won't help a laptop with its lid closed and no external display, because that is a hardware sleep path it doesn't control. Several commands need sudo, and flags change slightly between macOS releases, so man caffeinate (and its cousins) is the source of truth for your version.
The real value is narrower and more practical: for the dozen small jobs you do every week, the answer is often already on the machine, it's scoped to a single command, and it leaves no setting behind for you to forget about.
Sometimes the best developer tool is the one that was installed before you were.