Available disk space shrinking on Mac OS X? Check your log files.

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

$ du -smc * | sort -rn | head -n 10

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 ./ -type f \( -iname '*.log' -o -iname '*.txt'  \)  -size +5M -print0 2>/dev/null | xargs -0 ls -lh

That means:

  • 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 xargs)
  • 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.

  1. “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.” []

4 thoughts on “Available disk space shrinking on Mac OS X? Check your log files.”

  1. shoreacres

    If only I could do that mentally! I could stand to gain some space.

  2. the prince of malgeria

    more room for photos of cats. because that is what the internet is for! :-)

    1. sarahstaebler

      Very interesting! I also have an Air…and with it of course the normal concerns about disk space. Either I did it wrong, or my Mac didn’t have those big log files for mail. Oh well! Thanks for sharing this fix!

      1. cliff1976

        Sorry sarahstaebler — an earlier version of this post didn’t account for WordPress’s “helpful” conversion of apostrophe characters into opening and closing single-quotation marks. Try running the command again now — I’ve forced the apostrophes to remain.

        A few things to note (for any reader, not just sarahstaebler), perhaps:

        1. With that command, I’m not looking specifically for log files from Mail.app, but rather files over five MB in size with a *.txt or *.log file name suffix from anywhere in the current working directory or below it. You might also want to run that command from the /Applications directory or elsewhere — not just your home directory.
        2. Adjust the file size option from +5M to something else if you like.
        3. Be careful on the command line. You can break stuff.

What's your take on it?

This site uses Akismet to reduce spam. Learn how your comment data is processed.