Force Dropbox on Mac OS X to Respect Your Disk Space

closeThis post was published 5 years 5 months 19 days ago. A number of changes have been made to the site since then, so please contact me if anything is broken or seems wrong.

Dropbox is one of those tools without which it’s probably no longer possible for me to live. It just syncs files between my computers, and it makes those same files accessible through any Web browser. It’s not like my love for it is any secret.

The Problem

But it so happens that over the last year or so, I’ve increasingly run into a pretty major issue: Dropbox on my MacBook Pro will happily fill its .dropbox.cache folder with gigabytes upon gigabytes of files, sometimes filling 50+GB of disk space before finally the system chokes up and apps start crashing because, as Finder says, the hard drive has “Zero bytes free”. The system will pop up warnings that “Your startup disk is almost full”, but if the machine is unattended for several hours straight (overnight, during the day when I haven’t taken it to class, etc.) those warnings don’t help.

It seems the issue happens when a program makes lots of small updates to big files tracked by Dropbox. Other computers start accumulating several copies of each file in the .dropbox.cache folder, and they start eating up disk space pretty fast. Apparently the Dropbox client doesn’t have any logic built into it to prune the cache based on some reasonable size constraint—at least, not on Mac OS X; I’ve never encountered this issue on a Windows machine. So it’ll happily keep sticking previous versions of big changed files into its cache until the drive is completely full, then complain that it “Can’t sync; not enough free disk space”—even though that’s its own fault.

The Fix

Let’s just say I got tired of waiting for the Dropboxers to fix this. The solution I came up with is simple, taking just one line in my user crontab:

*/20 * * * * find -E /Users/dgw/Dropbox/.dropbox.cache -type f -regex '.*/[0-9]{4}-[0-9]{2}-[0-9]{2}/.*' -cmin +60 -exec rm {} \;

If you’re unfamiliar with crontab syntax, let me explain. Each line in a crontab file on OS X (and most other Unix-like systems) consists of 6 values, separated by tab characters: which minute to run the job; which hour to run the job; which day of the month to run the job; which weekday to run the job; and the command to run. Setting the first to */20 and the next four fields to * has the effect of running the command every 20 minutes. The last value, the command itself, uses the find utility to locate any file (-type f) in Dropbox’s cache (/Users/dgw/Dropbox/.dropbox.cache and -regex '.*/[0-9]{4}-[0-9]{2}-[0-9]{2}/.*) that is more than an hour old (-cmin +60) and delete each file it finds with rm (-exec rm {} \;).1

To set this up for yourself, do the following:2

  1. Open
  2. Run crontab -e
  3. Press i to enter vim’s insert mode
  4. Type */20 and four * characters, each followed by Tab (these five values should line up under the first five column headings, #min, hour, mday, month, & wday)
  5. Copy and paste (using Cmd+V) the command shown above, replacing /Users/dgw/Dropbox with the path to your Dropbox folder3
  6. Hit Esc to exit vim’s insert mode
  7. Type ZZ (two capital Zs) to save the file and quit vim
  8. vim will close and you will see the message crontab: installing new crontab in Terminal

Now, every 20 minutes, your Mac will automatically delete any of Dropbox’s cached files older than an hour. This will make it extremely hard (if not impossible) for Dropbox to single-handedly fill your hard drive to bursting.

Note that the numeric values are just what works best for me. */20 just means every 20 minutes; you could make it */15 for every 15 minutes, 0 for on the hour, 30 for half-past every hour, etc. -cmin +60 means files that were created (added to the cache) more than an hour ago, but this could be -cmin +180 for files that are more than three hours old or -cmin +30 for files more than half an hour old, etc. I initially had -cmin +120 until I ran into a particularly “productive” day on Dropbox’s part and had to cut down on its cache more aggressively.

The Caveats

The only potential downside I can think of is that, because you’re deleting things from Dropbox’s cache of changed and deleted file versions, restoring one of those previous versions or a deleted file will almost always mean having to download it again from Dropbox’s servers. If you regularly edit or delete files, only to restore a previous version within a day or two, this might not be something you want to do unless Dropbox is unrelenting in filling up your hard drive with cache files.

Again, the ideal fix would be for the Dropboxers to code in some logic that keeps Dropbox’s cache from filling your Mac’s hard drive in the first place. But until and unless they do, this is the little hack around the problem that I’ll be using.

  1. Yes, these are standard GNU/Linux commands. I linked to the OS X manpages because this tip targets OS X, but I don’t believe there are any huge differences between the Mac and Linux implementations. []
  2. I’ve had it in place for about six weeks and never had any problems, but <insert standard disclaimers about implementing this at your own risk>. []
  3. If you don’t know this path, it’s easy to find: Right-click your Dropbox folder and select “Get Info”. In the info dialog, the path is under “General”, labeled “Where:”, and it’s probably something like /Users/yourusername/Dropbox unless you picked a custom Dropbox folder location. []


I am an avid technology and software user, in addition to being reasonably well-versed in CSS, JavaScript, HTML, PHP, Python, and (though it still scares me) Perl. Aside from my technological tendencies, I am also a theatre technician, sound designer, violinist, singer, and actor.

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail (or subscribe without commenting)

Comments are subject to moderation, and are licensed for display in perpetuity once posted. Learn more.