Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

1.7 million empty directories under /private/var/folders/.../com.apple.metadata.mdworker/

I was wondering my OmniDiskSweeper kept crashing on me, so I decided to run 'opensnoop' on the process and see what the final item it was examining was. It was /private/var/folders/x7/83y6yl750knffcx262sw1lbm0000gn/C/com.apple.metadata When I tried to 'ls' it, it hung, 'ls -f' also hung, 'find ... print' hung. In the end, I wrote a small perl program to "opendir" and then "readdir" and count the items. There were 1,736,396 empty directories contained there.


Normal Unix utilities failed to start removing, so I modified my program to 'rmdir' each one.


Now, Omnidisksweeper works and I'm guessing a lot more will work as well.


Any ideas why com.apple.metadata.mdworker should have so many empty subdirectories?


Since I removed them a couple of hours ago, another 370 have appeared.


Running fully patched Mojave 10.14.6

Posted on Jan 12, 2022 6:07 AM

Reply

Similar questions

8 replies

Jan 12, 2022 8:53 AM in response to apjimmy

We are fellow users and not members of the macOS development team. The private/var/folders destination is where randomly named system folder structures and temporary application files are stored. I have never attempted to remove anything in that folder path, and do not recommend that you do either.


As you noticed, this is an active operating system destination that continues to create random directory hierarchy. This is normal. If you reboot your Mac on a regular basis, some of this cruft will get cleaned up by the operating system.

Jan 12, 2022 9:09 AM in response to VikingOSX

I rebooted 2 days ago. I've been having the crashing program for about 3-4 weeks at least, so it look like a reboot does not clear out this directory. My Monterey MacBook only has 373 after 4 days up. The iMac I'm running on now has since increased to 853 files since my last posting, so it looks to be something is wrong. I seem to get 5-10 new directories created in that directory every minute.


/System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mdworker_shared -s mdworker-shared -c MDSImporterWorker -m com.apple.mdworker.shared has a PID of 93806 and the last subdirectory created was 93806.417925


Creating all these directories and never deleting them, can't be the correct working of the program surely?

Jan 12, 2022 9:36 AM in response to apjimmy

Your focusing on the dynamic operating system and application contents written into /private/var/folders is a colossal waste of your time. I simply treat it as a black box necessary for normal operating system function and ignore it.


The entire content in my /private/var/folders totals 3MB of storage. I can probably remove two videos from my home directory to external storage and reclaim that amount.


Continuing to remove content from /private/var/folders may cause you to bork your Mac too.

Jan 12, 2022 11:02 AM in response to VikingOSX

I wouldn't normally do anything under there anyway. It's just that this was causing instability in other programs:

OmnidiskSweeper was crashing; find was hanging (or just taking over 15 minutes to parse a directory - as good as hanging); 'rm' and 'ls' both didn't work. Even 'ls -f' hung on that directory. It does look like there may be an instability in the OS/utilities that is causing these to be created since the PID part is of the name keeps increasing. I've had this version around for a long time (installed in 2014) , and it was upgraded and not re-installed, so there may be some major cruft lying around that is causing the issue.


I think I'll just live with it for the time being until I eventually upgrade it to another OS.

Jan 12, 2022 11:43 AM in response to apjimmy

Start with this of M1 Mac...


Start up a Mac with Apple silicon in safe mode

On your Mac, choose Apple menu  > Shut Down.

After your Mac shuts down, wait 10 seconds.

Press and hold the power button on your Mac until the startup options window appears showing available startup disks and Options.

Select a startup disk.

Press and hold the Shift key, click Continue in Safe Mode, then release the Shift key.

To leave safe mode, restart your Mac normally, without pressing and holding any keys during startup.



Start with this if IntelMac...


Safe Boot, (holding Shift key down at startup), does the problem occur in Safe Mode? Could take 10 minutes.


Safe mode attempts to repair Disks & clears lots of caches & loads safe Drivers, & prevents loading of 3rd party extensions, so if Safe Mode works try again in regular boot.


You can use Drive DX to possibly get a better view of Drive health…

https://binaryfruit.com/drivedx

Feb 4, 2022 8:09 PM in response to apjimmy

I had a similar problem -- 1.67 million empty folders in "/private/var/folders/*/*/C/com.apple.metadata.mdworker".


Somehow Carbon Copy Cloner won't ignore them when creating a boot clone and I simply manually forced CCC to ignore the folder when making a clone.


However, these folders seems to be a source of problem when upgrading the OS, so I followed the instruction here to delete them: https://mrmacintosh.com/macos-upgrade-to-big-sur-failed-stuck-progress-bar-fix-prevention/


Hope you and other will find it useful.



Feb 6, 2022 1:44 AM in response to BDAqua

Thanks for the confirmation that it's not just me. Until I upgrade to Monterey, I just run my perl script every day or so to keep the directory numbers low. Since the files look to be cache files for pics of mdworker that have died, I've not seen any bad results. The article gives a couple of examples of shell to remove the files. Here's the perl code that I run which did the job.

#!/usr/bin/perl
$b="/private/var/folders/x7/83y6yl750knffcx262sw1lbm0000gn/C/com.apple.metadata.mdworker";
opendir(F,$b) or die;
$i=0;
while (readdir F) {
    next if /^\.|\.\./;
    if ( -d "$b/$_" ) {
        rmdir "$b/$_" or warn "rmdir failed on $b/$_\n";
    }
    $i++;
}
print "$i directories identified under $b\n";

1.7 million empty directories under /private/var/folders/.../com.apple.metadata.mdworker/

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.