All Posts by Date or last 15, 30, 90 or 180 days.
also by Lloyd: photography and

Links on this site earn me fees or commissions.
As an Amazon Associate I earn from qualifying purchases @AMAZON

Consult with Lloyd: cameras, computers, backup, etc...
Lloyd’s Patreon
Designed for the most demanding needs of photographers and videographers.
Connect and charge all of your devices through a single Thunderbolt or USB-C port.

How To Prevent System Sleep while a Terminal Command is Running: caffeinate

As part of my work, I frequently work remotely, relying on a cellular data via a personal hot spot on my iPhone.

Even with a cell phone booster, internet speed can be quite limited (think 10K/sec at times!), and sometimes flaky too—remote areas don’t exactly have great cell phone coverage, if at allm and an hours-long driving round trip is a huge time-waster.

Here’s a nasty little behavior of macOS: it doesn’t much care what you are doing in something like Terminal—computation, network access, disk access, etc are all ignored. So you take a short break, only to find that macOS has put the machine to sleep and effectively aborted the job.


I use a source code management system for my web servers called git, and I frequently do a git push to sync my local development system to the server:

git push

But if macOS sleeps the system, the process goes to sleep, and when it wakes up the network connection is aborted. All that cellular data gone to waste, and job not done.

The solution is to prevent system sleep until the push is done using 'caffeinate':

caffeinate git push

Since I do this a lot, I like to make a shortcut (alias) for it:

alias push="caffeinate git push"

Example 2

Suppose you want to verify a large volume 'Photos' using IntegrityChecker. You want the system to sleep only after the verify has finished.

caffeinate icj verify Photos

View all handpicked deals...

Apple 16.2" MacBook Pro with M1 Max Chip (Late 2021, Space Gray)
$3499 $2399
SAVE $1100 | Terms of Use | PRIVACY POLICY
Contact | About Lloyd Chambers | Consulting | Photo Tours
Mailing Lists | RSS Feeds | Twitter
Copyright © 2020 diglloyd Inc, all rights reserved.
Display info: __RETINA_INFO_STATUS__