My MacBook only has 250 GB of storage, but 130 GB of storage space went missing for over a year. So, where did the storage space go? and how is it all Apple’s fault?
I checked every file and directory, and used various apps to assess what took up my storage space. However, I couldn’t account for about 130 GB of storage space on my Mac. For over a year, I wrongly attributed the storage space to unicorn file-system features like snapshots. The problem began when MacOS migrated to the Apple File System (APFS), and everyone and their pets attributed the problem to vague APFS related issues.
Upon closer inspection of my disk, however, I found where the missing storage space had gone. It was all taken by junk files stored in my hidden DARWIN_USER_CACHE_DIR
directory. The rest of this article explores where to find this directory, what it’s for, and what Apple can do better to prevent this from happening.
The “primary” user cache directory is stored in ~/Library/Caches/
directory in your Home folder. This directory is where programs are supposed to store cache files. Cache files are files that programs can recreate by redownloading them from the internet or by performing a local operation on another set of files. The directory is excluded by Time Machine and other back-up programs. Cache files are generally not considered to be valuable. You safely delete these files without losing any valuable data.
Many online tutorials will advise you to quit every program and delete the contents of this cache directory if you’re running out of storage space. It’s well-known in the Mac professional community.
Then there’s another “user cache” directory called DARWIN_USER_CACHE_DIR
, a relic from the early days of MacOS. It’s a hidden cache directory that’s located outside your Home directory. Its location isn’t a secret, but you must execute the getconf DARWIN_USER_CACHE_DIR
command in the Terminal to find where it’s located. Each user account on your Mac has its own DARWIN_USER_CACHE_DIR
directory.
The files in the DARWIN_USER_CACHE_DIR
directory accounted for 135 out of the 174 GBs of “other” files reported by the Storage Management app in MacOS. The Storage Management app doesn’t provide any details on what or where these “other” files are located. They can be anything anywhere on your system disk.
The directory is under-utilized in modern versions of MacOS. Everyone seems to stick to the ~/Library/Caches/
directory instead. In exploring my DARWIN_USER_CACHE_DIR
directory, I mostly found cache automatically generated by MacOS on behalf of third-party programs. I even found some software trial-license control files hidden away there as well. (Delete them to extend your free 30-day trial!)
I also found about 130 GB of failed Xcode downloads in a subdirectory belonging to the Apple App Store app. As it turns out, the App Store downloads into this cache directory before moving the completed download into place on the disk. For whatever reason, I found partially downloaded versions of Xcode that had built up in this directory going back years.
There’s a more appropriate directory to stage downloads in, however. Files that aren’t opened or used in the DARWIN_USER_TEMP_DIR
directory (different from DARWIN_USER_CACHE_DIR
) are automatically deleted after three–four days. If Apple had used this directory instead, its App Store mistakes would have been deleted within a few days. No harm is done.
MacOS has an option to automatically delete files from your Trash directory after 30 days. However, it doesn’t have an option to delete unused files from its cache directories. I say it’s high time Apple added an option to automatically clean out its cache directories too!
Here’s how simple it would be for Apple to implement this feature. You can follow along at home to get your Mac to clean itself periodically. Be very careful when you’re following these steps. Take your time to do it right. Make sure you’ve backed up important data first.
- Open the Terminal app (you can find it with Spotlight).
- Type
getconf DARWIN_USER_CACHE_DIR
and press Enter. - Copy the directory string it outputs for later (it should look something like
/var/folders/something-random/C
). - Type
sudo nano /etc/defaults/periodic.conf
and press Enter. - Type in your password when prompted, and press Enter again.
- Type the following into the file:
Enter the directory path you got in the third step. The two space-separated values must be enclosed in straight quotation marks. /tmp
is a special alias that means DARWIN_USER_TEMP_DIR
(for all users) and is the option’s default value.
- Press Control + X, then Y, and Enter.
- Reboot your Mac.
—and you’re done. You’ve just implemented a new feature on your Mac. MacOS will now automatically delete unused cache files after three days. You may also want to add the /Users/your-name/Library/Caches/
directory to the space-separated list in daily_clean_tmps_dirs
.
You can change the deletion time to ten days by setting the daily_clean_tmps_days="10"
option below the daily_clean_tmps_dirs
option (the default is three days). I recommend setting it to at least 10–14 days. You’ll want to set it to no less than how often you reboot (not suspend/resume, but reboot) your Mac. Add some days of margin for safety to allow programs that run at boot to open and extend their cache files lifetimes. Some programs may misbehave if their cache files are deleted without a reboot cycle.
You can learn more about what the various options in that configuration file do by typing man periodic.conf
into the Terminal app. You shouldn’t have to, but here we are.