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

Thank you for buying via links and ads on this site,
which earn me advertising fees or commissions.
As an Amazon Associate I earn from qualifying purchases.

Other World Computing...
B&H Photo...
As an Amazon Associate I earn from qualifying purchases.
Upgrade the memory of your 2020 iMac up to 128GB
Upgrade the memory of your 2020 iMac up to 128GB

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 13.3" MacBook Pro M1 Chip with Retina Display (Late 2020, Silver)
$1299 $1049
SAVE $250 | 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__