Code Linux MAC UNIX

Prevent Hard Drive from Going To Sleep or Spinning Down

If you own an external Western Digital drive like myself, you may have noticed that the drive has a built-in sleep function that spins down the drive if not used in a 10 minute time period. This feature is really annoying to me. Every time I attempted to access a file on my external, Finder would hang until the drive spun back up.

Here’s a quick and dirty solution.

Create a script that touches a hidden file every 5 minutes. I added the script to my crontab, which I talked about HERE.

I created a file called and added the following script.

# Prevent your hard drive from going to sleep 

wdMyBook=$(/sbin/mount | grep -i mybook | /usr/bin/wc -c)

if [ $wdMyBook -gt 0 ]
    touch /Volumes/MyBook/.hiddenfile
$ crontab -l
*/5 * * * * /Users/tommye/

It basically looks for a drive called MyBook, if it exists, touch a hidden file on the drive. The -gt is equivalent to greater than. This script can be applied to any drive, not just MyBook. All you need to do is change the directory path and grep option. It’s a pretty basic script.

Note: Don’t forget to apply executable permissions.

$ chmod +x

I personally have a 6TB (two 3TB drives) drive configured with a Raid 1, so if any drive were to fail, the other will take over without any data loss.