I have a Mac Book Air with 120 GB of storage built-in. I accumulate a fair amount of useless files through my normal usage, and I try to get rid of it periodically, storing the files I want to retain for the long-term elsewhere. Today I did my usual purge of videos, pictures, screenshots, documents and other assorted crap and found that my available disk space was still much less than I expected, and it was not immediately clear why. Turns out the culprits were some huge log files from the Apple Mail.app.
I started my research on the command line, using
to find the biggest files/directories in my home directory1. By far, the
~/Library directory was taking up the most space. Inside that directory, the
Containers directory was the biggest. Inside that directory,
com.apple.mail was the biggest. I kept digging deeper until I found several multi-gigabyte log files in
~/Library/Containers/com.apple.mail/Data/Library/Logs/Mail — one over 17 GB! — among many other, much smaller log files.
I found this discussion thread indicating it’s safe to delete those log files. I didn’t want to do that blindly — big log files like that could mean an ongoing problem between Mail.app and my IMAP provider(s), or, even worse, some kind of surreptitious mail activity between my Mac and the servers (yikes!).
Taking a closer look at the attributes of the biggest log files, I could see they were last modified a few weeks ago or had their first entries from around then. I recall having reconfigured one of my IMAP mail accounts on this machine around then, so I was confident the giant log files were resulting from the Mail.app’s resynchronization.
So I erased the biggest files with
rm and regained about 25 GB of disk space. On a machine with “only” 120 available in total, that’s a lot!
Here is how I’m going to look for big log files in the future:
- Find me files that are files (as opposed to directories or special files) in or below this directory,
- case-insensitively matching ‘log’ or ‘txt’ filename suffixes,
- which are bigger than 5 megabytes in size
- and then print them to screen null-terminatedly (for input to
- discarding any errors
- and list them for me with human-readable file sizes
The next time I’m running low on disk space and can’t immediately figure out why, I’ll look here first.
- “Show me the diskspace used, for all files in this directory, in megabytes, with a summary, and then sort those results numerically in descending order, and then show me only the first 10 rows.” [↩]